2 Copyright (C) 2012 Paul Davis
3 Inspired by code from Ben Loftis @ Harrison Consoles
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #ifndef PLATFORM_WINDOWS
27 #include <sys/utsname.h>
30 #include <curl/curl.h>
32 #include <glibmm/miscutils.h>
34 #include "pbd/compose.h"
35 #include "pbd/pthread_utils.h"
37 #include "ardour/filesystem_paths.h"
38 #include "ardour/rc_configuration.h"
43 using namespace ARDOUR;
45 #ifndef PLATFORM_WINDOWS // no pingback for windows, so far
47 curl_write_data (char *bufptr, size_t size, size_t nitems, void *ptr)
49 /* we know its a string */
51 string* sptr = (string*) ptr;
53 for (size_t i = 0; i < nitems; ++i) {
54 for (size_t n = 0; n < size; ++n) {
55 if (*bufptr == '\n') {
69 std::string announce_path;
71 ping_call (const std::string& v, const std::string& a)
72 : version (v), announce_path (a) {}
78 ping_call* cm = static_cast<ping_call*> (arg);
83 curl_global_init (CURL_GLOBAL_NOTHING);
84 c = curl_easy_init ();
86 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, curl_write_data);
87 curl_easy_setopt (c, CURLOPT_WRITEDATA, &return_str);
88 char errbuf[CURL_ERROR_SIZE];
89 curl_easy_setopt (c, CURLOPT_ERRORBUFFER, errbuf);
94 url = Config->get_osx_pingback_url ();
95 #elif defined PLATFORM_WINDOWS
96 url = Config->get_windows_pingback_url ();
98 url = Config->get_linux_pingback_url ();
101 if (url.compare (0, 4, "http") != 0) {
106 char* v = curl_easy_escape (c, cm->version.c_str(), cm->version.length());
111 #ifndef PLATFORM_WINDOWS
119 string uts = string_compose ("%1 %2 %3 %4", utb.sysname, utb.release, utb.version, utb.machine);
123 query = curl_easy_escape (c, utb.sysname, strlen (utb.sysname));
124 s = string_compose ("s=%1", query);
129 query = curl_easy_escape (c, utb.release, strlen (utb.release));
130 s = string_compose ("r=%1", query);
135 query = curl_easy_escape (c, utb.machine, strlen (utb.machine));
136 s = string_compose ("m=%1", query);
140 // this is hilarious: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724429%28v=vs.85%29.aspx
141 # if ( defined(__x86_64__) || defined(_M_X64) )
146 #endif /* PLATFORM_WINDOWS */
148 curl_easy_setopt (c, CURLOPT_URL, url.c_str());
152 if (curl_easy_perform (c) == 0) {
155 curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &http_status);
157 if (http_status != 200) {
158 std::cerr << "Bad HTTP status" << std::endl;
162 if ( return_str.length() > 140 ) { // like a tweet :)
163 std::cerr << "Announcement string is too long (probably behind a proxy)." << std::endl;
165 std::cerr << "Announcement is: " << return_str << std::endl;
167 //write announcements to local file, even if the
168 //announcement is empty
170 std::ofstream annc_file (cm->announce_path.c_str());
173 annc_file << return_str;
177 std::cerr << "curl failed: " << errbuf << std::endl;
180 curl_easy_cleanup (c);
187 void pingback (const string& version, const string& announce_path)
189 ping_call* cm = new ping_call (version, announce_path);
192 pthread_create_and_store ("pingback", &thread, _pingback, cm);