Moonlight-XboxOG latest
Moonlight Xbox OG is a port of the Moonlight Game Streaming client to the original Xbox console.
host_records.cpp File Reference

Implements host record models and utilities. More...

#include "src/app/host_records.h"
#include <algorithm>
#include <cctype>
#include <cstddef>
#include <limits>
#include <utility>
#include <vector>
#include "src/platform/error_utils.h"
Include dependency graph for host_records.cpp:

Functions

void app::append_parsed_host_record (std::string_view line, std::size_t lineNumber, ParseHostRecordsResult *result)
 Parse one serialized host-record line and append it to the accumulated result.
 
std::string app::build_default_host_display_name (std::string_view normalizedAddress)
 Build a controller-friendly default display name for a host.
 
bool app::contains_host_address (const std::vector< HostRecord > &records, std::string_view normalizedAddress, uint16_t port=0)
 Return whether a host list already contains an endpoint.
 
uint16_t app::effective_host_port (uint16_t port)
 Return the effective TCP port for a host record.
 
bool app::host_matches_endpoint (const HostRecord &host, std::string_view normalizedAddress, uint16_t port)
 Return whether a host record matches a specific endpoint.
 
bool app::is_valid_ipv4_address (std::string_view address)
 Return whether a string is a valid IPv4 address.
 
std::string app::normalize_ipv4_address (std::string_view address)
 Normalize a user-provided IPv4 address.
 
ParseHostRecordsResult app::parse_host_records (std::string_view serializedRecords)
 Parse host records from the stable serialized text format.
 
std::string app::serialize_host_records (const std::vector< HostRecord > &records)
 Serialize host records into a stable tab-separated text format.
 
const char * app::to_string (HostReachability reachability)
 Return a stable lowercase label for a host reachability state.
 
const char * app::to_string (PairingState pairingState)
 Return a stable lowercase label for a pairing state.
 
bool app::try_parse_host_port (std::string_view portText, uint16_t *parsedPort)
 Parse a user-supplied TCP port string.
 
bool app::validate_host_record (const HostRecord &record, std::string *errorMessage=nullptr)
 Validate a host record before saving or serializing it.
 

Detailed Description

Implements host record models and utilities.

Function Documentation

◆ append_parsed_host_record()

void app::append_parsed_host_record ( std::string_view line,
std::size_t lineNumber,
ParseHostRecordsResult * result )

Parse one serialized host-record line and append it to the accumulated result.

Parameters
lineRaw tab-separated line to parse.
lineNumberOne-based line number used in parse errors.
resultAggregate parse result to update.

◆ build_default_host_display_name()

std::string app::build_default_host_display_name ( std::string_view normalizedAddress)

Build a controller-friendly default display name for a host.

Parameters
normalizedAddressCanonical IPv4 address.
Returns
Generated display label.

◆ contains_host_address()

bool app::contains_host_address ( const std::vector< HostRecord > & records,
std::string_view normalizedAddress,
uint16_t port = 0 )

Return whether a host list already contains an endpoint.

Parameters
recordsSaved hosts to search.
normalizedAddressCanonical IPv4 address to match.
portStored port override to match.
Returns
true when a saved host uses the same address and effective port.

◆ effective_host_port()

uint16_t app::effective_host_port ( uint16_t port)

Return the effective TCP port for a host record.

Parameters
portStored port override where zero means default.
Returns
Effective host port.

◆ host_matches_endpoint()

bool app::host_matches_endpoint ( const HostRecord & host,
std::string_view normalizedAddress,
uint16_t port )

Return whether a host record matches a specific endpoint.

A host matches when the canonical host address equals normalizedAddress and port matches any known effective host endpoint (stored HTTP port, resolved HTTP port, or HTTPS port).

Parameters
hostHost record to test.
normalizedAddressCanonical IPv4 address to compare.
portEndpoint port where zero means DEFAULT_HOST_PORT.
Returns
true when the host record can be reached by the given endpoint.

◆ is_valid_ipv4_address()

bool app::is_valid_ipv4_address ( std::string_view address)

Return whether a string is a valid IPv4 address.

Parameters
addressCandidate IPv4 address.
Returns
true when the address can be normalized.

◆ normalize_ipv4_address()

std::string app::normalize_ipv4_address ( std::string_view address)

Normalize a user-provided IPv4 address.

Parameters
addressCandidate IPv4 address.
Returns
Canonical dotted-quad form, or an empty string when invalid.

◆ parse_host_records()

ParseHostRecordsResult app::parse_host_records ( std::string_view serializedRecords)

Parse host records from the stable serialized text format.

Parameters
serializedRecordsSerialized host record text.
Returns
Parsed records plus any non-fatal line errors.

◆ serialize_host_records()

std::string app::serialize_host_records ( const std::vector< HostRecord > & records)

Serialize host records into a stable tab-separated text format.

The serialized form preserves the saved host identity plus any cached app-list entries and their local visibility or artwork metadata.

Parameters
recordsHost records to serialize.
Returns
Serialized text suitable for disk persistence.

◆ to_string() [1/2]

const char * app::to_string ( HostReachability reachability)

Return a stable lowercase label for a host reachability state.

Parameters
reachabilityReachability state to stringify.
Returns
Stable lowercase label.

◆ to_string() [2/2]

const char * app::to_string ( PairingState pairingState)

Return a stable lowercase label for a pairing state.

Parameters
pairingStatePairing state to stringify.
Returns
Stable lowercase label.

◆ try_parse_host_port()

bool app::try_parse_host_port ( std::string_view portText,
uint16_t * parsedPort )

Parse a user-supplied TCP port string.

Parameters
portTextText entered by the user.
parsedPortOutput port override where zero means default.
Returns
true when the port string is valid.

◆ validate_host_record()

bool app::validate_host_record ( const HostRecord & record,
std::string * errorMessage = nullptr )

Validate a host record before saving or serializing it.

Parameters
recordHost record to validate.
errorMessageOptional output for a validation error.
Returns
true when the record is valid.