2013-03-08 11:42:37 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2013-2015 John Emmas <john@creativepost.co.uk>
|
|
|
|
* Copyright (C) 2013-2018 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2013-03-08 11:42:37 -05:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <cstring>
|
|
|
|
|
2015-07-11 16:20:55 -04:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
#include <windows.h>
|
2015-07-11 16:35:59 -04:00
|
|
|
#include <glibmm.h>
|
2015-07-11 16:20:55 -04:00
|
|
|
#else
|
2013-03-08 11:42:37 -05:00
|
|
|
#include <sys/utsname.h>
|
2013-07-13 08:38:17 -04:00
|
|
|
#endif
|
|
|
|
|
2015-10-05 16:10:58 -04:00
|
|
|
#include "pbd/gstdio_compat.h"
|
2013-03-08 11:42:37 -05:00
|
|
|
#include <glibmm/miscutils.h>
|
|
|
|
|
|
|
|
#include "pbd/compose.h"
|
|
|
|
#include "pbd/pthread_utils.h"
|
2013-03-09 08:44:22 -05:00
|
|
|
|
2013-03-08 11:42:37 -05:00
|
|
|
#include "ardour/filesystem_paths.h"
|
2013-03-09 08:44:22 -05:00
|
|
|
#include "ardour/rc_configuration.h"
|
2013-03-08 11:42:37 -05:00
|
|
|
|
2016-07-18 10:46:17 -04:00
|
|
|
#include "ardour_http.h"
|
2013-03-08 11:42:37 -05:00
|
|
|
#include "pingback.h"
|
2016-06-21 19:23:30 -04:00
|
|
|
#include "utils.h"
|
2013-03-08 11:42:37 -05:00
|
|
|
|
|
|
|
using std::string;
|
2013-03-09 08:44:22 -05:00
|
|
|
using namespace ARDOUR;
|
2013-03-08 11:42:37 -05:00
|
|
|
|
|
|
|
struct ping_call {
|
|
|
|
std::string version;
|
|
|
|
std::string announce_path;
|
|
|
|
|
|
|
|
ping_call (const std::string& v, const std::string& a)
|
|
|
|
: version (v), announce_path (a) {}
|
|
|
|
};
|
|
|
|
|
2015-07-11 19:54:44 -04:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
static bool
|
|
|
|
_query_registry (const char *regkey, const char *regval, std::string &rv) {
|
|
|
|
HKEY key;
|
|
|
|
DWORD size = PATH_MAX;
|
|
|
|
char tmp[PATH_MAX+1];
|
|
|
|
|
|
|
|
if ( (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ, &key))
|
|
|
|
&& (ERROR_SUCCESS == RegQueryValueExA (key, regval, 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
|
|
|
|
)
|
|
|
|
{
|
|
|
|
rv = Glib::locale_to_utf8 (tmp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ | KEY_WOW64_32KEY, &key))
|
|
|
|
&& (ERROR_SUCCESS == RegQueryValueExA (key, regval, 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
|
|
|
|
)
|
|
|
|
{
|
|
|
|
rv = Glib::locale_to_utf8 (tmp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-03-08 11:42:37 -05:00
|
|
|
static void*
|
|
|
|
_pingback (void *arg)
|
|
|
|
{
|
2020-03-29 08:56:50 -04:00
|
|
|
pthread_set_name ("Pingback");
|
2016-07-18 10:46:17 -04:00
|
|
|
ArdourCurl::HttpGet h;
|
|
|
|
|
2013-03-08 11:42:37 -05:00
|
|
|
ping_call* cm = static_cast<ping_call*> (arg);
|
|
|
|
string return_str;
|
|
|
|
//initialize curl
|
|
|
|
|
|
|
|
string url;
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
2013-03-09 08:44:22 -05:00
|
|
|
url = Config->get_osx_pingback_url ();
|
2015-07-11 15:45:26 -04:00
|
|
|
#elif defined PLATFORM_WINDOWS
|
|
|
|
url = Config->get_windows_pingback_url ();
|
2013-03-08 11:42:37 -05:00
|
|
|
#else
|
2013-03-09 08:44:22 -05:00
|
|
|
url = Config->get_linux_pingback_url ();
|
2013-03-08 11:42:37 -05:00
|
|
|
#endif
|
|
|
|
|
2015-07-11 15:45:26 -04:00
|
|
|
if (url.compare (0, 4, "http") != 0) {
|
|
|
|
delete cm;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-18 10:46:17 -04:00
|
|
|
char* v = h.escape (cm->version.c_str(), cm->version.length());
|
2013-03-08 11:42:37 -05:00
|
|
|
url += v;
|
|
|
|
url += '?';
|
2016-07-18 10:46:17 -04:00
|
|
|
h.free (v);
|
2013-03-08 11:42:37 -05:00
|
|
|
|
2015-07-11 15:45:26 -04:00
|
|
|
#ifndef PLATFORM_WINDOWS
|
|
|
|
struct utsname utb;
|
|
|
|
|
|
|
|
if (uname (&utb)) {
|
|
|
|
delete cm;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-11 16:19:08 -04:00
|
|
|
//string uts = string_compose ("%1 %2 %3 %4", utb.sysname, utb.release, utb.version, utb.machine);
|
2013-03-08 11:42:37 -05:00
|
|
|
string s;
|
|
|
|
char* query;
|
|
|
|
|
2016-07-18 10:46:17 -04:00
|
|
|
query = h.escape (utb.sysname, strlen (utb.sysname));
|
2013-03-08 11:42:37 -05:00
|
|
|
s = string_compose ("s=%1", query);
|
|
|
|
url += s;
|
|
|
|
url += '&';
|
2016-07-18 10:46:17 -04:00
|
|
|
h.free (query);
|
2013-03-08 11:42:37 -05:00
|
|
|
|
2016-07-18 10:46:17 -04:00
|
|
|
query = h.escape (utb.release, strlen (utb.release));
|
2013-03-08 11:42:37 -05:00
|
|
|
s = string_compose ("r=%1", query);
|
|
|
|
url += s;
|
|
|
|
url += '&';
|
2016-07-18 10:46:17 -04:00
|
|
|
h.free (query);
|
2013-03-08 11:42:37 -05:00
|
|
|
|
2016-07-18 10:46:17 -04:00
|
|
|
query = h.escape (utb.machine, strlen (utb.machine));
|
2013-03-08 11:42:37 -05:00
|
|
|
s = string_compose ("m=%1", query);
|
|
|
|
url += s;
|
2016-07-18 10:46:17 -04:00
|
|
|
h.free (query);
|
2015-07-11 15:45:26 -04:00
|
|
|
#else
|
2015-07-11 19:54:44 -04:00
|
|
|
std::string val;
|
|
|
|
if (_query_registry("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ProductName", val)) {
|
2016-07-18 10:46:17 -04:00
|
|
|
char* query = h.escape (val.c_str(), strlen (val.c_str()));
|
2015-07-11 19:54:44 -04:00
|
|
|
url += "r=";
|
|
|
|
url += query;
|
2015-07-11 19:16:44 -04:00
|
|
|
url += '&';
|
2016-07-18 10:46:17 -04:00
|
|
|
h.free (query);
|
2015-07-11 19:16:44 -04:00
|
|
|
} else {
|
|
|
|
url += "r=&";
|
|
|
|
}
|
|
|
|
|
2015-07-11 19:54:44 -04:00
|
|
|
if (_query_registry("Hardware\\Description\\System\\CentralProcessor\\0", "Identifier", val)) {
|
2015-07-12 13:27:23 -04:00
|
|
|
// remove "Family X Model YY Stepping Z" tail
|
|
|
|
size_t cut = val.find (" Family ");
|
|
|
|
if (string::npos != cut) {
|
|
|
|
val = val.substr (0, cut);
|
|
|
|
}
|
2016-07-18 10:46:17 -04:00
|
|
|
char* query = h.escape (val.c_str(), strlen (val.c_str()));
|
2015-07-11 19:54:44 -04:00
|
|
|
url += "m=";
|
|
|
|
url += query;
|
2015-07-11 16:19:08 -04:00
|
|
|
url += '&';
|
2016-07-18 10:46:17 -04:00
|
|
|
h.free (query);
|
2015-07-11 16:19:08 -04:00
|
|
|
} else {
|
|
|
|
url += "m=&";
|
|
|
|
}
|
|
|
|
|
2015-07-11 15:45:26 -04:00
|
|
|
# if ( defined(__x86_64__) || defined(_M_X64) )
|
2015-07-11 16:19:08 -04:00
|
|
|
url += "s=Windows64";
|
2015-07-11 15:45:26 -04:00
|
|
|
# else
|
2015-07-11 16:19:08 -04:00
|
|
|
url += "s=Windows32";
|
2015-07-11 15:45:26 -04:00
|
|
|
# endif
|
2015-07-11 16:19:08 -04:00
|
|
|
|
2015-07-11 15:45:26 -04:00
|
|
|
#endif /* PLATFORM_WINDOWS */
|
2013-03-08 11:42:37 -05:00
|
|
|
|
2018-06-02 13:24:17 -04:00
|
|
|
return_str = h.get (url, false);
|
2013-03-08 11:42:37 -05:00
|
|
|
|
2016-07-18 10:46:17 -04:00
|
|
|
if (!return_str.empty ()) {
|
2013-03-08 11:42:37 -05:00
|
|
|
if ( return_str.length() > 140 ) { // like a tweet :)
|
|
|
|
std::cerr << "Announcement string is too long (probably behind a proxy)." << std::endl;
|
|
|
|
} else {
|
2020-03-25 13:39:32 -04:00
|
|
|
std::cout << "Announcement is: " << return_str << std::endl;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-03-08 11:42:37 -05:00
|
|
|
//write announcements to local file, even if the
|
|
|
|
//announcement is empty
|
2015-09-08 10:38:17 -04:00
|
|
|
|
|
|
|
FILE* fout = g_fopen (cm->announce_path.c_str(), "wb");
|
|
|
|
|
|
|
|
if (fout) {
|
2015-09-08 15:21:28 -04:00
|
|
|
fwrite (return_str.c_str(), sizeof(char), return_str.length (), fout);
|
2015-09-08 10:38:17 -04:00
|
|
|
fclose (fout);
|
2013-03-08 11:42:37 -05:00
|
|
|
}
|
|
|
|
}
|
2013-03-08 14:51:35 -05:00
|
|
|
} else {
|
2017-04-20 18:12:20 -04:00
|
|
|
#ifndef NDEBUG
|
|
|
|
std::cerr << "pingback: " << h.error () << std::endl;
|
|
|
|
#endif
|
2013-03-08 11:42:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
delete cm;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace ARDOUR {
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
void pingback (const string& version, const string& announce_path)
|
2013-03-08 11:42:37 -05:00
|
|
|
{
|
2016-06-21 19:23:30 -04:00
|
|
|
if (ARDOUR_UI_UTILS::running_from_source_tree ()) {
|
|
|
|
/* we don't ping under these conditions, because the user is
|
|
|
|
probably just paul or robin :)
|
|
|
|
*/
|
2016-06-14 12:21:46 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-08 11:42:37 -05:00
|
|
|
ping_call* cm = new ping_call (version, announce_path);
|
|
|
|
pthread_t thread;
|
|
|
|
|
|
|
|
pthread_create_and_store ("pingback", &thread, _pingback, cm);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|