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.
24 #ifdef PLATFORM_WINDOWS
28 #include <sys/utsname.h>
31 #include "pbd/gstdio_compat.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"
40 #include "ardour_http.h"
45 using namespace ARDOUR;
49 std::string announce_path;
51 ping_call (const std::string& v, const std::string& a)
52 : version (v), announce_path (a) {}
55 #ifdef PLATFORM_WINDOWS
57 _query_registry (const char *regkey, const char *regval, std::string &rv) {
59 DWORD size = PATH_MAX;
62 if ( (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ, &key))
63 && (ERROR_SUCCESS == RegQueryValueExA (key, regval, 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
66 rv = Glib::locale_to_utf8 (tmp);
70 if ( (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ | KEY_WOW64_32KEY, &key))
71 && (ERROR_SUCCESS == RegQueryValueExA (key, regval, 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
74 rv = Glib::locale_to_utf8 (tmp);
86 ArdourCurl::HttpGet h;
88 ping_call* cm = static_cast<ping_call*> (arg);
95 url = Config->get_osx_pingback_url ();
96 #elif defined PLATFORM_WINDOWS
97 url = Config->get_windows_pingback_url ();
99 url = Config->get_linux_pingback_url ();
102 if (url.compare (0, 4, "http") != 0) {
107 char* v = h.escape (cm->version.c_str(), cm->version.length());
112 #ifndef PLATFORM_WINDOWS
120 //string uts = string_compose ("%1 %2 %3 %4", utb.sysname, utb.release, utb.version, utb.machine);
124 query = h.escape (utb.sysname, strlen (utb.sysname));
125 s = string_compose ("s=%1", query);
130 query = h.escape (utb.release, strlen (utb.release));
131 s = string_compose ("r=%1", query);
136 query = h.escape (utb.machine, strlen (utb.machine));
137 s = string_compose ("m=%1", query);
142 if (_query_registry("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", val)) {
143 char* query = h.escape (val.c_str(), strlen (val.c_str()));
152 if (_query_registry("Hardware\\Description\\System\\CentralProcessor\\0", "Identifier", val)) {
153 // remove "Family X Model YY Stepping Z" tail
154 size_t cut = val.find (" Family ");
155 if (string::npos != cut) {
156 val = val.substr (0, cut);
158 char* query = h.escape (val.c_str(), strlen (val.c_str()));
167 # if ( defined(__x86_64__) || defined(_M_X64) )
168 url += "s=Windows64";
170 url += "s=Windows32";
173 #endif /* PLATFORM_WINDOWS */
175 return_str = h.get (url);
177 if (!return_str.empty ()) {
178 if ( return_str.length() > 140 ) { // like a tweet :)
179 std::cerr << "Announcement string is too long (probably behind a proxy)." << std::endl;
181 std::cerr << "Announcement is: " << return_str << std::endl;
183 //write announcements to local file, even if the
184 //announcement is empty
186 FILE* fout = g_fopen (cm->announce_path.c_str(), "wb");
189 fwrite (return_str.c_str(), sizeof(char), return_str.length (), fout);
194 std::cerr << "curl failed: " << h.error () << std::endl;
203 void pingback (const string& version, const string& announce_path)
205 if (ARDOUR_UI_UTILS::running_from_source_tree ()) {
206 /* we don't ping under these conditions, because the user is
207 probably just paul or robin :)
212 ping_call* cm = new ping_call (version, announce_path);
215 pthread_create_and_store ("pingback", &thread, _pingback, cm);