9 #include <sys/utsname.h>
10 #include <curl/curl.h>
12 #include <glibmm/fileutils.h>
13 #include <glibmm/miscutils.h>
15 #include "pbd/compose.h"
16 #include "pbd/strsplit.h"
17 #include "pbd/convert.h"
19 #include "ardour/callback.h"
20 #include "ardour/filesystem_paths.h"
24 #define PING_URL "http://ardour.org/pingback/versioncheck"
25 #define OFF_THE_HOOK ".offthehook"
28 curl_write_data (char *bufptr, size_t size, size_t nitems, void *ptr)
30 /* we know its a string */
32 string* sptr = (string*) ptr;
34 for (size_t i = 0; i < nitems; ++i) {
35 for (size_t n = 0; n < size; ++n) {
36 if (*bufptr == '\n') {
56 string hangup = Glib::build_filename (ARDOUR::user_config_directory().to_string(), OFF_THE_HOOK);
58 if ((fd = ::open (hangup.c_str(), O_RDWR|O_CREAT, 0600)) >= 0) {
66 string hangup = Glib::build_filename (ARDOUR::user_config_directory().to_string(), OFF_THE_HOOK);
67 ::unlink (hangup.c_str());
73 string hangup = Glib::build_filename (ARDOUR::user_config_directory().to_string(), OFF_THE_HOOK);
74 return Glib::file_test (hangup, Glib::FILE_TEST_EXISTS);
78 call_the_mothership (const string& version)
80 /* check if the user says never to do this
83 if (mothership_blocked()) {
89 std::string versionstr;
95 curl_global_init (CURL_GLOBAL_NOTHING);
97 c = curl_easy_init ();
102 data = string_compose ("version=%1&platform=%2 %3 %4", version, utb.sysname, utb.release, utb.machine);
106 data += string_compose ("&watermark=%1", wm);
109 curl_easy_setopt(c, CURLOPT_POSTFIELDS, data.c_str());
110 curl_easy_setopt(c, CURLOPT_URL, PING_URL);
111 curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, curl_write_data);
112 curl_easy_setopt(c, CURLOPT_WRITEDATA, &versionstr);
114 std::cerr << "Callback to ardour.org ...\n";
116 char errbuf[CURL_ERROR_SIZE];
117 curl_easy_setopt(c, CURLOPT_ERRORBUFFER, errbuf);
119 if (curl_easy_perform (c) == 0) {
120 cerr << "Current release is " << versionstr << endl;
123 vector<string> current;
125 split (version, ours, '.');
126 split (versionstr, current, '.');
128 if (ours.size() == 3 && current.size() == 3) {
135 ours_n[0] = atoi (ours[0]);
136 ours_n[1] = atoi (ours[1]);
137 ours_n[2] = atoi (ours[2]);
139 current_n[0] = atoi (current[0]);
140 current_n[1] = atoi (current[1]);
141 current_n[2] = atoi (current[2]);
143 if (ours_n[0] < current_n[0] ||
144 ((ours_n[0] == current_n[0]) && (ours_n[1] < current_n[1])) ||
145 ((ours_n[0] == current_n[0]) && (ours_n[1] == current_n[1]) && (ours_n[2] < current_n[2]))) {
151 cerr << "Unusual local version: " << version << endl;
155 curl_easy_cleanup (c);