remove old a3_curl API and switch some curl calls
authorRobin Gareus <robin@gareus.org>
Mon, 18 Jul 2016 14:10:35 +0000 (16:10 +0200)
committerRobin Gareus <robin@gareus.org>
Mon, 18 Jul 2016 14:46:59 +0000 (16:46 +0200)
Keep freesound-moocher as is until freesound-apiv2 branch is merged
or rebased.

gtk2_ardour/add_video_dialog.cc
gtk2_ardour/luainstance.cc
gtk2_ardour/luawindow.cc
gtk2_ardour/utils_videotl.cc
gtk2_ardour/utils_videotl.h
gtk2_ardour/video_image_frame.cc
gtk2_ardour/video_timeline.cc

index 126c1618126d9b10a18a30d2992227f4d891db79..bd94c370baa70bb60015abf18ca0a77ea5c79f78 100644 (file)
@@ -34,6 +34,7 @@
 #include "ardour_ui.h"
 
 #include "add_video_dialog.h"
+#include "ardour_http.h"
 #include "utils_videotl.h"
 #include "pbd/i18n.h"
 
@@ -504,7 +505,7 @@ AddVideoDialog::harvid_request(std::string u)
 
        harvid_list->clear();
 
-       char *res = a3_curl_http_get(url, &status);
+       char* res = ArdourCurl::http_get (url, &status);
        if (status != 200) {
                printf("request failed\n"); // XXX
                harvid_path.set_text(" - request failed -");
@@ -684,7 +685,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 = a3_curl_http_get(url, NULL);
+       char* data = ArdourCurl::http_get (url, NULL);
        if (!data) {
                printf("image preview request failed %s\n", url);
                imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
index 4d3ea5f777a0e0e50fb433b05f53e8b0ac7ed7dc..fe91bb95620e2ab8ff99722396c8106f5447cccd 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "LuaBridge/LuaBridge.h"
 
+#include "ardour_http.h"
 #include "ardour_ui.h"
 #include "public_editor.h"
 #include "region_selection.h"
@@ -347,16 +348,6 @@ const char *luasignalstr[] = {
 }; // namespace
 
 
-std::string lua_http_get (const char *u) {
-       char *rv = a3_curl_http_get (u, NULL);
-       if (!rv) {
-               return "";
-       }
-       std::string s (rv);
-       free (rv);
-       return s;
-}
-
 ////////////////////////////////////////////////////////////////////////////////
 
 #define xstr(s) stringify(s)
@@ -549,7 +540,7 @@ LuaInstance::register_classes (lua_State* L)
        luabridge::getGlobalNamespace (L)
                .beginNamespace ("ArdourUI")
 
-               .addFunction ("curl_http_get", &lua_http_get)
+               .addFunction ("http_get", (std::string (*)(const std::string&))&ArdourCurl::http_get)
 
                .beginStdList <ArdourMarker*> ("ArdourMarkerList")
                .endClass ()
index e8ab438a15d490704fdcaec1d00319cd089e2354..4733bcbeec482ea1b3121781176ef0e7c70500f8 100644 (file)
@@ -380,7 +380,7 @@ LuaWindow::import_script ()
        // TODO convert a few URL (eg. pastebin) to raw.
 #if 0
        char *url = "http://pastebin.com/raw/3UMkZ6nV";
-       char *rv = a3_curl_http_get (url, 0);
+       char *rv = ArdourCurl::http_get (url, 0);
        if (rv) {
                new_script ();
                Glib::RefPtr<Gtk::TextBuffer> tb (entry.get_buffer());
index 0a521a19357bbd2d1ec94450ba9a458e252900d4..684bbf920c49832b7ba55269fd94bee81ac72937 100644 (file)
 #include <string>
 #include <cerrno>
 #include <gtkmm.h>
-#include <curl/curl.h>
 
 #include "pbd/error.h"
+
 #include "ardour/ardour.h"
 #include "ardour/session_directory.h"
-#include "video_image_frame.h"
-#include "utils_videotl.h"
+
+#include "ardour_http.h"
 #include "utils.h"
+#include "utils_videotl.h"
+#include "video_image_frame.h"
 
 #ifdef WAF_BUILD
 #include "gtk2ardour-version.h"
@@ -264,14 +266,13 @@ 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());
-       char *res = a3_curl_http_get(url, NULL);
-       if (!res) {
+       std::string res = ArdourCurl::http_get (url);
+       if (res.empty ()) {
                return false;
        }
 
        std::vector<std::vector<std::string> > lines;
-       ParseCSV(std::string(res), lines);
-       free(res);
+       ParseCSV(res, lines);
 
        if (lines.empty() || lines.at(0).empty() || lines.at(0).size() != 6) {
                return false;
@@ -308,69 +309,3 @@ VideoUtils::video_draw_cross (Glib::RefPtr<Gdk::Pixbuf> img)
        }
 }
 
-
-extern "C" {
-#include <curl/curl.h>
-
-       struct A3MemoryStruct {
-               char *data;
-               size_t size;
-       };
-
-       static size_t
-       WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) {
-               size_t realsize = size * nmemb;
-               struct A3MemoryStruct *mem = (struct A3MemoryStruct *)data;
-
-               mem->data = (char *)realloc(mem->data, mem->size + realsize + 1);
-               if (mem->data) {
-                       memcpy(&(mem->data[mem->size]), ptr, realsize);
-                       mem->size += realsize;
-                       mem->data[mem->size] = 0;
-               }
-               return realsize;
-       }
-
-       char *a3_curl_http_get (const char *u, int *status) {
-               CURL *curl;
-               CURLcode res;
-               struct A3MemoryStruct chunk;
-               long int httpstatus;
-               if (status) *status = 0;
-               if (strncmp("http://", u, 7) && strncmp("https://", u, 8)) return NULL;
-
-               chunk.data=NULL;
-               chunk.size=0;
-
-               curl = curl_easy_init();
-               if(!curl) return NULL;
-               curl_easy_setopt(curl, CURLOPT_URL, u);
-
-               curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
-               curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
-               curl_easy_setopt(curl, CURLOPT_USERAGENT, PROGRAM_NAME VERSIONSTRING);
-               curl_easy_setopt(curl, CURLOPT_TIMEOUT, ARDOUR_CURL_TIMEOUT);
-               curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-#ifdef CURLERRORDEBUG
-               char curlerror[CURL_ERROR_SIZE] = "";
-               curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlerror);
-#endif
-
-               res = curl_easy_perform(curl);
-               curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpstatus);
-               curl_easy_cleanup(curl);
-               if (status) *status = httpstatus;
-               if (res) {
-#ifdef CURLERRORDEBUG
-                       printf("a3_curl_http_get() failed: %s\n", curlerror);
-#endif
-                       return NULL;
-               }
-               if (httpstatus != 200) {
-                       free (chunk.data);
-                       chunk.data = NULL;
-               }
-               return (chunk.data);
-       }
-
-} /* end extern "C" */
index a7d0908a34a32b50017950aec643b1583741353a..40425fc5e8e6c25e659a337157b7edb2cf2c09ac 100644 (file)
@@ -56,8 +56,4 @@ bool video_query_info (
                );
 };
 
-extern "C" {
-       char *a3_curl_http_get (const char *u, int *status);
-}
-
 #endif /* __gtk_ardour_video_utils_h__ */
index 7480468cc7912377dcd0790cdf969cd35676ecb2..093f2351077ed32ef52222f5b28cc36020370fe0 100644 (file)
 #include <sigc++/bind.h>
 #include "ardour/tempo.h"
 
-#include "video_image_frame.h"
-#include "public_editor.h"
-#include "canvas/container.h"
-#include "utils_videotl.h"
-
 #include <gtkmm2ext/utils.h>
 #include <pthread.h>
 
+#include "canvas/container.h"
+
+#include "ardour_http.h"
+#include "public_editor.h"
+#include "utils_videotl.h"
+#include "video_image_frame.h"
+
 #include "pbd/i18n.h"
 
 using namespace std;
@@ -208,7 +210,7 @@ http_get_thread (void *arg) {
        int timeout = 1000; // * 5ms -> 5sec
        char *res = NULL;
        do {
-               res=a3_curl_http_get(url, &status);
+               res = ArdourCurl::http_get (url, &status);
                if (status == 503) Glib::usleep(5000); // try-again
        } while (status == 503 && --timeout > 0);
 
index 0e109f32d4af186c971768076e46fd4de41299d6..3468ff2c705eaa53df763be105eaac17c49d7d02 100644 (file)
@@ -26,6 +26,7 @@
 #include "ardour/session_directory.h"
 
 #include "ardour_ui.h"
+#include "ardour_http.h"
 #include "public_editor.h"
 #include "gui_thread.h"
 #include "utils_videotl.h"
@@ -556,7 +557,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=a3_curl_http_get(url, NULL);
+       char* res = ArdourCurl::http_get (url, NULL);
        if (res) {
                if (strstr(res, "status: ok, online.")) { ok = true; }
                free(res);
@@ -578,7 +579,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=a3_curl_http_get(url, NULL);
+       char* res = ArdourCurl::http_get (url, NULL);
        if (!res) {
                return false;
        }
@@ -674,7 +675,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=a3_curl_http_get(url, NULL);
+       char* res = ArdourCurl::http_get (url, NULL);
        if (res) {
                free (res);
        }