2 Copyright (C) 2012 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <sys/types.h>
28 #include <sys/utsname.h>
29 #include <curl/curl.h>
31 #include <glibmm/fileutils.h>
32 #include <glibmm/miscutils.h>
34 #include "pbd/compose.h"
35 #include "pbd/strsplit.h"
36 #include "pbd/convert.h"
38 #include "ardour/filesystem_paths.h"
42 #define PING_URL "http://ardour.org/pingback/versioncheck"
43 #define OFF_THE_HOOK ".offthehook"
46 curl_write_data (char *bufptr, size_t size, size_t nitems, void *ptr)
48 /* we know its a string */
50 string* sptr = (string*) ptr;
52 for (size_t i = 0; i < nitems; ++i) {
53 for (size_t n = 0; n < size; ++n) {
54 if (*bufptr == '\n') {
74 string hangup = Glib::build_filename (ARDOUR::user_config_directory(), OFF_THE_HOOK);
76 if ((fd = ::open (hangup.c_str(), O_RDWR|O_CREAT, 0600)) >= 0) {
84 string hangup = Glib::build_filename (ARDOUR::user_config_directory(), OFF_THE_HOOK);
85 ::unlink (hangup.c_str());
91 string hangup = Glib::build_filename (ARDOUR::user_config_directory(), OFF_THE_HOOK);
92 return Glib::file_test (hangup, Glib::FILE_TEST_EXISTS);
96 call_the_mothership (const string& version)
98 /* check if the user says never to do this
101 if (mothership_blocked()) {
107 std::string versionstr;
113 curl_global_init (CURL_GLOBAL_NOTHING);
115 c = curl_easy_init ();
120 data = string_compose ("version=%1&platform=%2 %3 %4", version, utb.sysname, utb.release, utb.machine);
124 data += string_compose ("&watermark=%1", wm);
127 curl_easy_setopt(c, CURLOPT_POSTFIELDS, data.c_str());
128 curl_easy_setopt(c, CURLOPT_URL, PING_URL);
129 curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, curl_write_data);
130 curl_easy_setopt(c, CURLOPT_WRITEDATA, &versionstr);
132 std::cerr << "Callback to ardour.org ...\n";
134 char errbuf[CURL_ERROR_SIZE];
135 curl_easy_setopt(c, CURLOPT_ERRORBUFFER, errbuf);
137 if (curl_easy_perform (c) == 0) {
138 cerr << "Current release is " << versionstr << endl;
141 vector<string> current;
143 split (version, ours, '.');
144 split (versionstr, current, '.');
146 if (ours.size() == 3 && current.size() == 3) {
153 ours_n[0] = atoi (ours[0]);
154 ours_n[1] = atoi (ours[1]);
155 ours_n[2] = atoi (ours[2]);
157 current_n[0] = atoi (current[0]);
158 current_n[1] = atoi (current[1]);
159 current_n[2] = atoi (current[2]);
161 if (ours_n[0] < current_n[0] ||
162 ((ours_n[0] == current_n[0]) && (ours_n[1] < current_n[1])) ||
163 ((ours_n[0] == current_n[0]) && (ours_n[1] == current_n[1]) && (ours_n[2] < current_n[2]))) {
169 cerr << "Unusual local version: " << version << endl;
173 curl_easy_cleanup (c);