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/filesystem_paths.h"
23 #define PING_URL "http://ardour.org/pingback/versioncheck"
24 #define OFF_THE_HOOK ".offthehook"
27 curl_write_data (char *bufptr, size_t size, size_t nitems, void *ptr)
29 /* we know its a string */
31 string* sptr = (string*) ptr;
33 for (size_t i = 0; i < nitems; ++i) {
34 for (size_t n = 0; n < size; ++n) {
35 if (*bufptr == '\n') {
55 string hangup = Glib::build_filename (ARDOUR::user_config_directory().to_string(), OFF_THE_HOOK);
57 if ((fd = ::open (hangup.c_str(), O_RDWR|O_CREAT, 0600)) >= 0) {
65 string hangup = Glib::build_filename (ARDOUR::user_config_directory().to_string(), OFF_THE_HOOK);
66 ::unlink (hangup.c_str());
72 string hangup = Glib::build_filename (ARDOUR::user_config_directory().to_string(), OFF_THE_HOOK);
73 return Glib::file_test (hangup, Glib::FILE_TEST_EXISTS);
77 call_the_mothership (const string& version)
79 /* check if the user says never to do this
82 if (mothership_blocked()) {
88 std::string versionstr;
94 curl_global_init (CURL_GLOBAL_NOTHING);
96 c = curl_easy_init ();
101 data = string_compose ("version=%1&platform=%2 %3 %4", version, utb.sysname, utb.release, utb.machine);
105 data += string_compose ("&watermark=%1", wm);
108 curl_easy_setopt(c, CURLOPT_POSTFIELDS, data.c_str());
109 curl_easy_setopt(c, CURLOPT_URL, PING_URL);
110 curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, curl_write_data);
111 curl_easy_setopt(c, CURLOPT_WRITEDATA, &versionstr);
113 std::cerr << "Callback to ardour.org ...\n";
115 char errbuf[CURL_ERROR_SIZE];
116 curl_easy_setopt(c, CURLOPT_ERRORBUFFER, errbuf);
118 if (curl_easy_perform (c) == 0) {
119 cerr << "Current release is " << versionstr << endl;
122 vector<string> current;
124 split (version, ours, '.');
125 split (versionstr, current, '.');
127 if (ours.size() == 3 && current.size() == 3) {
134 ours_n[0] = atoi (ours[0]);
135 ours_n[1] = atoi (ours[1]);
136 ours_n[2] = atoi (ours[2]);
138 current_n[0] = atoi (current[0]);
139 current_n[1] = atoi (current[1]);
140 current_n[2] = atoi (current[2]);
142 if (ours_n[0] < current_n[0] ||
143 ((ours_n[0] == current_n[0]) && (ours_n[1] < current_n[1])) ||
144 ((ours_n[0] == current_n[0]) && (ours_n[1] == current_n[1]) && (ours_n[2] < current_n[2]))) {
150 cerr << "Unusual local version: " << version << endl;
154 curl_easy_cleanup (c);