51 lines
1.8 KiB
C++
51 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include "protocol/websocket_transport.h"
|
|
|
|
#include <array>
|
|
#include <cstddef>
|
|
|
|
namespace borla {
|
|
|
|
// Endpoint block carried by the OTA check response. The OTA service is the
|
|
// only channel that can repoint a fielded device at a different realtime
|
|
// server, so the URL/token pair travels with the firmware manifest rather than
|
|
// with the realtime protocol itself.
|
|
struct OtaEndpointConfig {
|
|
std::array<char, kWebsocketUrlCapacity> url{};
|
|
std::array<char, kWebsocketTokenCapacity> token{};
|
|
bool has_url = false;
|
|
bool has_token = false;
|
|
|
|
bool HasAny() const { return has_url || has_token; }
|
|
};
|
|
|
|
// True for endpoints that ship as build/staging defaults. A saved value that
|
|
// matches one of these is treated as "not deliberately provisioned" and is
|
|
// replaced by the current default, so a device that once talked to a retired
|
|
// staging host recovers on its own instead of retrying it forever.
|
|
bool IsRolloverEndpoint(const char* url);
|
|
|
|
// Some deployments answer with a wildcard bind address in the websocket block.
|
|
// Substitute the host the OTA request itself was answered by, which is the
|
|
// only host the device is known to be able to reach.
|
|
// Returns false when `url` has no 0.0.0.0 host, when `ota_url` has no usable
|
|
// host, or when the result would not fit; `output` is only written on true.
|
|
bool SubstituteWildcardHost(
|
|
const char* url,
|
|
const char* ota_url,
|
|
char* output,
|
|
size_t capacity);
|
|
|
|
// Full resolution used by OtaService: applies SubstituteWildcardHost, then
|
|
// falls back to `default_url` when the result is a rollover endpoint.
|
|
// Returns false when nothing usable could be produced.
|
|
bool ResolveRealtimeUrl(
|
|
const char* url,
|
|
const char* ota_url,
|
|
const char* default_url,
|
|
char* output,
|
|
size_t capacity);
|
|
|
|
} // namespace borla
|