Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

110 lines
2.7 KiB
C++
Raw Permalink Normal View History

2022-05-03 03:07:22 -07:00
//
// xemu Reporting
//
// Title compatibility and bug report submission.
//
// Copyright (C) 2020-2025 Matt Borgerson
2022-05-03 03:07:22 -07:00
//
// 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, see <http://www.gnu.org/licenses/>.
//
#include "qemu/osdep.h"
#include "qemu/http.h"
2020-04-26 16:49:45 -07:00
#include <glib.h>
#include <glib/gi18n.h>
2020-04-26 04:46:40 -07:00
#include <stdio.h>
2022-05-03 03:07:22 -07:00
#include "reporting.hh"
#include <nlohmann/json.hpp>
2020-04-26 04:46:40 -07:00
using json = nlohmann::json;
static const char *compat_report_endpoint_url = "https://reports.xemu.app/compatibility";
2020-04-26 04:46:40 -07:00
CompatibilityReport::CompatibilityReport()
{
}
CompatibilityReport::~CompatibilityReport()
{
}
const std::string &CompatibilityReport::GetSerializedReport()
{
json report = {
{"token", token},
{"xemu_version", xemu_version},
2026-01-04 23:04:49 -07:00
{"xemu_branch", ""},
2020-04-26 04:46:40 -07:00
{"xemu_commit", xemu_commit},
{"xemu_date", xemu_date},
{"os_platform", os_platform},
{"os_version", os_version},
{"cpu", cpu},
{"gl_vendor", gl_vendor},
{"gl_renderer", gl_renderer},
{"gl_version", gl_version},
{"gl_shading_language_version", gl_shading_language_version},
{"compat_rating", compat_rating},
{"compat_comments", compat_comments},
2020-04-26 16:49:45 -07:00
{"xbe_headers", xbe_headers},
2020-04-26 04:46:40 -07:00
};
2021-03-03 03:24:24 -07:00
serialized = report.dump(2);
2020-04-26 04:46:40 -07:00
return serialized;
}
2020-04-27 16:26:17 -07:00
bool CompatibilityReport::Send()
2020-04-26 04:46:40 -07:00
{
const std::string &s = GetSerializedReport();
int res = http_post_json(compat_report_endpoint_url, s.c_str(), NULL);
if (res < 0) {
2020-04-27 16:26:17 -07:00
result_code = -1;
result_msg = "Failed to connect";
return false;
2020-04-26 04:46:40 -07:00
}
switch(res) {
2020-04-27 16:26:17 -07:00
case 200:
result_msg = "Ok";
return true;
case 400:
case 411:
result_msg = "Invalid request";
return false;
case 403:
result_msg = "Invalid token";
return false;
case 409:
result_msg = "Please upgrade to latest version";
return false;
2020-04-27 16:26:17 -07:00
case 413:
result_msg = "Report too long";
return false;
default:
result_msg = "Unknown error occurred";
2020-04-27 16:26:17 -07:00
return false;
}
2020-04-26 04:46:40 -07:00
}
2020-04-26 16:49:45 -07:00
void CompatibilityReport::SetXbeData(struct xbe *xbe)
{
assert(xbe != NULL);
assert(xbe->headers != NULL);
assert(xbe->headers_len > 0);
// base64 encode all XBE headers to be sent with the report
gchar *buf = g_base64_encode(xbe->headers, xbe->headers_len);
xbe_headers = buf;
g_free(buf);
}