4 #include <sys/utsname.h>
7 #include <glibmm/fileutils.h>
8 #include <glibmm/miscutils.h>
10 #include "pbd/compose.h"
11 #include "pbd/strsplit.h"
12 #include "pbd/convert.h"
14 #include "ardour/callback.h"
15 #include "ardour/filesystem_paths.h"
19 #define PING_URL "http://ardour.org/pingback/versioncheck"
22 curl_write_data (char *bufptr
, size_t size
, size_t nitems
, void *ptr
)
24 /* we know its a string */
26 string
* sptr
= (string
*) ptr
;
28 for (size_t i
= 0; i
< nitems
; ++i
) {
29 for (size_t n
= 0; n
< size
; ++n
) {
30 if (*bufptr
== '\n') {
48 call_the_mothership (const string
& version
)
50 /* check if the user says never to do this
53 string hangup
= Glib::build_filename (ARDOUR::user_config_directory().to_string(), ".offthehook");
55 if (Glib::file_test (hangup
, Glib::FILE_TEST_EXISTS
)) {
61 std::string versionstr
;
67 curl_global_init (CURL_GLOBAL_NOTHING
);
69 c
= curl_easy_init ();
74 data
= string_compose ("version=%1&platform=%2 %3 %4", version
, utb
.sysname
, utb
.release
, utb
.machine
);
78 data
+= string_compose ("&watermark=%1", wm
);
81 curl_easy_setopt(c
, CURLOPT_POSTFIELDS
, data
.c_str());
82 curl_easy_setopt(c
, CURLOPT_URL
, PING_URL
);
83 curl_easy_setopt(c
, CURLOPT_WRITEFUNCTION
, curl_write_data
);
84 curl_easy_setopt(c
, CURLOPT_WRITEDATA
, &versionstr
);
86 std::cerr
<< "Callback to ardour.org ...\n";
88 char errbuf
[CURL_ERROR_SIZE
];
89 curl_easy_setopt(c
, CURLOPT_ERRORBUFFER
, errbuf
);
91 if (curl_easy_perform (c
) == 0) {
92 cerr
<< "Current release is " << versionstr
<< endl
;
95 vector
<string
> current
;
97 split (version
, ours
, '.');
98 split (versionstr
, current
, '.');
100 if (ours
.size() == 3 && current
.size() == 3) {
107 ours_n
[0] = atoi (ours
[0]);
108 ours_n
[1] = atoi (ours
[1]);
109 ours_n
[2] = atoi (ours
[2]);
111 current_n
[0] = atoi (current
[0]);
112 current_n
[1] = atoi (current
[1]);
113 current_n
[2] = atoi (current
[2]);
115 if (ours_n
[0] < current_n
[0] ||
116 ((ours_n
[0] == current_n
[0]) && (ours_n
[1] < current_n
[1])) ||
117 ((ours_n
[0] == current_n
[0]) && (ours_n
[1] == current_n
[1]) && (ours_n
[2] < current_n
[2]))) {
123 cerr
<< "Unusual local version: " << version
<< endl
;
127 curl_easy_cleanup (c
);