actually read&parse current version from ardour.org, and pay attention to ~/.config...
[ardour2.git] / libs / ardour / callback.cc
blobe0c02e64d4633d1858dda4d10b2d1ddfaf83970a
1 #include <iostream>
2 #include <string>
3 #include <stdio.h>
4 #include <sys/utsname.h>
5 #include <curl/curl.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"
17 using namespace std;
19 #define PING_URL "http://ardour.org/pingback/versioncheck"
21 static size_t
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') {
31 break;
34 (*sptr) += *bufptr++;
38 return size * nitems;
41 static string
42 watermark ()
44 return "";
47 void
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)) {
56 return;
59 CURL* c;
60 struct utsname utb;
61 std::string versionstr;
63 if (uname (&utb)) {
64 return;
67 curl_global_init (CURL_GLOBAL_NOTHING);
69 c = curl_easy_init ();
71 string data;
72 string wm;
74 data = string_compose ("version=%1&platform=%2 %3 %4", version, utb.sysname, utb.release, utb.machine);
76 wm = watermark();
77 if (!wm.empty()) {
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;
94 vector<string> ours;
95 vector<string> current;
97 split (version, ours, '.');
98 split (versionstr, current, '.');
100 if (ours.size() == 3 && current.size() == 3) {
102 int ours_n[3];
103 int current_n[3];
105 using namespace PBD;
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]))) {
118 cerr << "TOO OLD\n";
119 } else {
120 cerr << "CURRENT\n";
122 } else {
123 cerr << "Unusual local version: " << version << endl;
127 curl_easy_cleanup (c);