remove unused SHUTTLE_FRACT constant
[ardour2.git] / libs / ardour / callback.cc
blob3a66836748ffa4cb47b3179b603ffb326ab24d8e
1 #include <iostream>
2 #include <string>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <cstdlib>
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"
22 using namespace std;
24 #define PING_URL "http://ardour.org/pingback/versioncheck"
25 #define OFF_THE_HOOK ".offthehook"
27 static size_t
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') {
37 break;
40 (*sptr) += *bufptr++;
44 return size * nitems;
47 static string
48 watermark ()
50 return string();
53 void
54 block_mothership ()
56 string hangup = Glib::build_filename (ARDOUR::user_config_directory().to_string(), OFF_THE_HOOK);
57 int fd;
58 if ((fd = ::open (hangup.c_str(), O_RDWR|O_CREAT, 0600)) >= 0) {
59 close (fd);
63 void
64 unblock_mothership ()
66 string hangup = Glib::build_filename (ARDOUR::user_config_directory().to_string(), OFF_THE_HOOK);
67 ::unlink (hangup.c_str());
70 bool
71 mothership_blocked ()
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);
77 void
78 call_the_mothership (const string& version)
80 /* check if the user says never to do this
83 if (mothership_blocked()) {
84 return;
87 CURL* c;
88 struct utsname utb;
89 std::string versionstr;
91 if (uname (&utb)) {
92 return;
95 curl_global_init (CURL_GLOBAL_NOTHING);
97 c = curl_easy_init ();
99 string data;
100 string wm;
102 data = string_compose ("version=%1&platform=%2 %3 %4", version, utb.sysname, utb.release, utb.machine);
104 wm = watermark();
105 if (!wm.empty()) {
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;
122 vector<string> ours;
123 vector<string> current;
125 split (version, ours, '.');
126 split (versionstr, current, '.');
128 if (ours.size() == 3 && current.size() == 3) {
130 int ours_n[3];
131 int current_n[3];
133 using namespace PBD;
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]))) {
146 cerr << "TOO OLD\n";
147 } else {
148 cerr << "CURRENT\n";
150 } else {
151 cerr << "Unusual local version: " << version << endl;
155 curl_easy_cleanup (c);