core: client API Majestic, modèles et CLI check

- libopenpu : validation VIN, modèles JSON (getAvailableUpdate, devices),
  classification ecuType -> type/guide, sélection des mises à jour
- couche Transport abstraite + implémentation libcurl (proxy env, redirections,
  streaming, timeout d'inactivité)
- tolérance au EOF TLS sans close_notify de la passerelle Majestic, limitée
  aux corps délimités par la fermeture (ni Content-Length ni chunked)
- openpu-cli : check / raw-devices / raw-updates
- tests doctest (VIN, parsing, classification, client API avec faux transport),
  fixtures dont une capture réelle anonymisée (NAC wave 2)
- qualité : presets CMake (debug, asan, tidy), .clang-tidy, tools/check.sh
  (tests, ASan/UBSan, valgrind, clang-tidy, cppcheck)
- validé contre l'API réelle sur 3 véhicules (NAC w4, RCC, NAC w2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WDASLCiN764v685boRVYar
This commit is contained in:
yann64andClaude Opus 5.5 committed 2026-11-28 17:45:27 +01:00
1 parent 660a420a3e
commit 95704f9882
28 files changed
+1877 -2

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
#pragma once
#include "openpu/http.hpp"
#include "openpu/models.hpp"
#include <stdexcept>
#include <string>
namespace openpu {
/// Backend endpoints. Defaults are those of the Peugeot build of the official application;
/// every field can be overridden (other brands, or a local mock server).
struct ApiConfig {
std::string devicesUrl = "https://api.groupe-psa.com/applications/majesticf/v1/devices/";
std::string updatesUrl = "https://api.groupe-psa.com/applications/majesticf/v1/getAvailableUpdate";
std::string clientId = "20a4cf7c-f5fb-41d5-9175-a6e23b9880e5";
/// Defaults overridden by OPENPU_DEVICES_URL, OPENPU_UPDATES_URL and OPENPU_CLIENT_ID when set.
static ApiConfig fromEnvironment();
};
class ApiError : public std::runtime_error {
public:
enum class Kind {
Network, ///< no HTTP response (offline, DNS, TLS, timeout)
Server, ///< unexpected HTTP status
BadResponse, ///< unparsable / unexpected body
InvalidVin, ///< rejected locally before any request
};
ApiError(Kind kind, long status, const std::string& what) : std::runtime_error(what), kind_(kind), status_(status) {}
Kind kind() const noexcept { return kind_; }
long status() const noexcept { return status_; }
private:
Kind kind_;
long status_;
};
class ApiClient {
public:
ApiClient(Transport& transport, ApiConfig config);
/// Does the VIN exist, and which head unit does it have?
/// A 404 on the devices endpoint yields `exists == false` (not an error).
VehicleCheck checkVehicle(const std::string& vin);
/// Latest firmware / map update for a vehicle whose type is already known.
AvailableUpdates getUpdates(const std::string& vin, HeadUnitType type);
/// Raw calls, exposed for diagnostics (openpu-cli --raw) and tests.
HttpResponse rawDevices(const std::string& vin);
HttpResponse rawUpdates(const std::string& vin, const std::vector<std::string>& softwareTypes);
const ApiConfig& config() const noexcept { return config_; }
private:
HttpResponse send(HttpRequest request);
static void requireValidVin(const std::string& vin);
Transport& transport_;
ApiConfig config_;
};
} // namespace openpu