RTE RBC 2oo2 Reference Application 0.1.0 build 0006685
SIL 4 2oo2 Dual-Site Fault-Tolerant ERTMS Radio Block Centre Reference Architecture
Loading...
Searching...
No Matches
gateway_c_config.c File Reference

Lightweight JSON configuration parser for Role C Gateway. More...

#include "gateway_c_config.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rte/oal/memory/rte_mem_util.h"
#include "common/common_config.h"
#include "common/rbc_wire_types.h"
Include dependency graph for gateway_c_config.c:

Go to the source code of this file.

Macros

#define MAX_CONFIG_FILE_SIZE   8192U

Functions

static const char * skip_whitespace (const char *p)
static const char * extract_string (const char *p, char *out, size_t out_size)
static const char * extract_uint32 (const char *p, uint32_t *out_val)
static const char * extract_uint32_checked (const char *p, uint32_t *out_val)
 Checked unsigned decimal parse, used for the socket buffer keys (REQ-OAL-NETLINK-015).
rte_status_t gateway_c_config_init_defaults (rte_example_site_t site, gateway_c_config_t *out_cfg)
static const char * skip_separator (const char *p)
static const char * extract_into (const char *p, char *dest, size_t dest_size)
static const char * extract_number_into (const char *p, uint32_t *field)
static const char * extract_buffer_size_into (const char *p, uint32_t *field)
static const char * parse_channel_prop (const char *p, const char *key, gateway_c_config_channel_t *ch, bool allow_identity)
 Parses the value of one channel property into ch.
static const char * parse_channel_object (const char *p, gateway_c_config_t *cfg, const char *fixed_name)
 Parses one channel object; p points at its '{'.
static const char * parse_channels_array (const char *p, gateway_c_config_t *cfg)
static const char * parse_channels_object (const char *p, gateway_c_config_t *cfg)
static const char * parse_top_level_value (const char *p, const char *key, gateway_c_config_t *cfg)
rte_status_t gateway_c_config_load_file (const char *filepath, gateway_c_config_t *out_cfg)
rte_status_t gateway_c_config_find_channel (const gateway_c_config_t *cfg, const char *channel_name, rte_netlink_config_t *out_netlink_cfg)
rte_status_t gateway_c_config_find_channel_by_id (const gateway_c_config_t *cfg, uint32_t channel_id, rte_netlink_config_t *out_netlink_cfg)

Detailed Description

Lightweight JSON configuration parser for Role C Gateway.

Definition in file gateway_c_config.c.

Macro Definition Documentation

◆ MAX_CONFIG_FILE_SIZE

#define MAX_CONFIG_FILE_SIZE   8192U

Definition at line 17 of file gateway_c_config.c.

Function Documentation

◆ skip_whitespace()

const char * skip_whitespace ( const char * p)
static

Definition at line 19 of file gateway_c_config.c.

◆ extract_string()

const char * extract_string ( const char * p,
char * out,
size_t out_size )
static

Definition at line 32 of file gateway_c_config.c.

◆ extract_uint32()

const char * extract_uint32 ( const char * p,
uint32_t * out_val )
static

Definition at line 60 of file gateway_c_config.c.

◆ extract_uint32_checked()

const char * extract_uint32_checked ( const char * p,
uint32_t * out_val )
static

Checked unsigned decimal parse, used for the socket buffer keys (REQ-OAL-NETLINK-015).

extract_uint32() relies on strtoul(), which accepts a sign ("-1" becomes UINT32_MAX), truncates a value above UINT32_MAX and stops at the first non-digit ("262144 KB" reads as 262144). It is kept unchanged for the older keys; this one rejects instead.

Parameters
pFirst character of the value (leading whitespace is skipped).
out_valWritten only on success.
Returns
Pointer past the digits, or NULL when the value is not one or more decimal digits, is above UINT32_MAX, or is followed (after optional whitespace) by anything other than ',' or '}' ("1 000 000", "256 * 1024", "1.5", a truncated file).

Definition at line 87 of file gateway_c_config.c.

◆ gateway_c_config_init_defaults()

rte_status_t gateway_c_config_init_defaults ( rte_example_site_t site,
gateway_c_config_t * out_cfg )

Definition at line 122 of file gateway_c_config.c.

◆ skip_separator()

const char * skip_separator ( const char * p)
static

Skips whitespace and one optional ',' separator.

Definition at line 140 of file gateway_c_config.c.

◆ extract_into()

const char * extract_into ( const char * p,
char * dest,
size_t dest_size )
static

Copies a string value into a fixed-size channel field (truncating).

Definition at line 151 of file gateway_c_config.c.

◆ extract_number_into()

const char * extract_number_into ( const char * p,
uint32_t * field )
static

Parses one numeric channel property; field may be NULL (value is consumed and dropped).

Definition at line 164 of file gateway_c_config.c.

◆ extract_buffer_size_into()

const char * extract_buffer_size_into ( const char * p,
uint32_t * field )
static

Parses one socket buffer size through extract_uint32_checked(); field may be NULL (value checked, dropped).

Definition at line 177 of file gateway_c_config.c.

◆ parse_channel_prop()

const char * parse_channel_prop ( const char * p,
const char * key,
gateway_c_config_channel_t * ch,
bool allow_identity )
static

Parses the value of one channel property into ch.

Parameters
chTarget channel, or NULL when the channel table is full (value is consumed and dropped).
allow_identityTrue for the array form, where "id" and "name" are properties; false for the object form, where the channel name is the enclosing key.
Returns
Pointer past the value, or NULL if the value is malformed.

Definition at line 196 of file gateway_c_config.c.

◆ parse_channel_object()

const char * parse_channel_object ( const char * p,
gateway_c_config_t * cfg,
const char * fixed_name )
static

Parses one channel object; p points at its '{'.

Parameters
fixed_nameChannel name taken from the enclosing key (object form), or NULL (array form).
Returns
Pointer past the closing '}', or NULL if malformed.

Definition at line 267 of file gateway_c_config.c.

◆ parse_channels_array()

const char * parse_channels_array ( const char * p,
gateway_c_config_t * cfg )
static

Parses "channels": [ {...}, ... ]; p points at '['. Returns pointer past ']' or NULL if malformed.

Definition at line 319 of file gateway_c_config.c.

◆ parse_channels_object()

const char * parse_channels_object ( const char * p,
gateway_c_config_t * cfg )
static

Parses "channels": { "<name>": {...}, ... }; p points at '{'. Returns pointer past '}' or NULL.

Definition at line 351 of file gateway_c_config.c.

◆ parse_top_level_value()

const char * parse_top_level_value ( const char * p,
const char * key,
gateway_c_config_t * cfg )
static

Dispatches one top-level "key": value pair. Returns pointer past the value, or NULL if malformed.

Definition at line 392 of file gateway_c_config.c.

◆ gateway_c_config_load_file()

rte_status_t gateway_c_config_load_file ( const char * filepath,
gateway_c_config_t * out_cfg )

Definition at line 435 of file gateway_c_config.c.

◆ gateway_c_config_find_channel()

rte_status_t gateway_c_config_find_channel ( const gateway_c_config_t * cfg,
const char * channel_name,
rte_netlink_config_t * out_netlink_cfg )

Definition at line 491 of file gateway_c_config.c.

◆ gateway_c_config_find_channel_by_id()

rte_status_t gateway_c_config_find_channel_by_id ( const gateway_c_config_t * cfg,
uint32_t channel_id,
rte_netlink_config_t * out_netlink_cfg )

Definition at line 522 of file gateway_c_config.c.