first pass a "phone home" facility for version tracking and update notification
[ardour.git] / libs / ardour / callback.cc
1 #include <iostream>
2 #include <string>
3
4 #include <sys/utsname.h>
5 #include <curl/curl.h>
6
7 #include "pbd/compose.h"
8 #include "ardour/callback.h"
9
10 using namespace std;
11
12 #define PING_URL "http://ardour.org/pingback/versioncheck"
13
14 static size_t
15 curl_write_data (char *bufptr, size_t size, size_t nitems, void *ptr)
16 {
17         return size * nitems;
18 }
19
20 static string
21 watermark ()
22 {
23         return "";
24 }
25
26 void
27 call_the_mothership (const string& version)
28 {
29         CURL* c;
30         struct utsname utb;
31
32         if (uname (&utb)) {
33                 return;
34         }
35         
36         curl_global_init (CURL_GLOBAL_NOTHING);
37
38         c = curl_easy_init ();
39
40         string data;
41         string wm;
42
43         data = string_compose ("version=%1&platform=%2 %3 %4", version, utb.sysname, utb.release, utb.machine);
44
45         wm = watermark();
46         if (!wm.empty()) {
47                 data += string_compose ("&watermark=%1", wm);
48         }
49         
50         curl_easy_setopt(c, CURLOPT_POSTFIELDS, data.c_str());
51         curl_easy_setopt(c, CURLOPT_URL, PING_URL);
52         curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, curl_write_data); 
53         curl_easy_setopt(c, CURLOPT_WRITEDATA, 0); 
54         
55         std::cerr << "Callback to ardour.org ...\n";
56
57         char errbuf[CURL_ERROR_SIZE];
58         curl_easy_setopt(c, CURLOPT_ERRORBUFFER, errbuf); 
59
60         if (curl_easy_perform (c) == 0) {
61
62         }
63         
64         curl_easy_cleanup (c);
65 }