Document of c-modernization-kit (porter) 1.0.0

Loading...
Searching...
No Matches
Macros | Functions
config.c File Reference

設定ファイル (INI 形式) 解析モジュール。 More...

`#include <ctype.h>`
`#include <inttypes.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <porter_const.h>`
`#include <porter_type.h>`
`#include "../infra/crypto/crypto.h"`
`#include "../infra/potrLog.h"`
`#include "config.h"`
Include dependency graph for config.c:

Go to the source code of this file.

## Macros
#define | CONFIG_LINE_MAX 256
| 設定ファイル 1 行の最大長。
#define | CONFIG_SECTION_MAX 64
| セクション名の最大長。
#define | CONFIG_KEY_MAX 64
| キー名の最大長。
#define | CONFIG_VAL_MAX 128
| 値文字列の最大長。

## Functions
static FILE * | open_config_file_read (const char *path)
static void | copy_cstr_trunc (char *dst, size_t dst_size, const char *src)
static void | trim (const char *src, char *buf, size_t buf_size)
static int | parse_kv (const char *line, char *key_out, size_t key_size, char *val_out, size_t val_size)
int | config_load_global (const char *config_path, PotrGlobalConfig *global)
| 設定ファイルから [global] セクションを読み込みます。
static void | apply_service_kv (const char *key, const char *val, PotrServiceDef *current)
int | config_load_service (const char *config_path, int64_t service_id, PotrServiceDef *def)
| 設定ファイルから指定サービスの定義を読み込みます。
int | config_list_service_ids (const char *config_path, int64_t **ids_out, int *count_out)
| 設定ファイルに登録されているすべてのサービス ID を列挙します。

## Detailed Description

設定ファイル (INI 形式) 解析モジュール。

Author
  c-modernization-kit sample team

Date
  2026/03/04

Version
  1.0.0

Copyright
  Copyright (C) CompanyName, Ltd. 2026. All rights reserved.

Definition in file config.c.

## Macro Definition Documentation

## ◆ CONFIG_LINE_MAX

#define CONFIG_LINE_MAX 256

設定ファイル 1 行の最大長。

Definition at line 28 of file config.c.

Referenced by config_list_service_ids(), config_load_global(), and config_load_service().

## ◆ CONFIG_SECTION_MAX

#define CONFIG_SECTION_MAX 64

セクション名の最大長。

Definition at line 31 of file config.c.

Referenced by config_list_service_ids(), config_load_global(), and config_load_service().

## ◆ CONFIG_KEY_MAX

#define CONFIG_KEY_MAX 64

キー名の最大長。

Definition at line 34 of file config.c.

Referenced by config_load_global(), config_load_service(), and parse_kv().

## ◆ CONFIG_VAL_MAX

#define CONFIG_VAL_MAX 128

値文字列の最大長。

Definition at line 37 of file config.c.

Referenced by config_load_global(), and config_load_service().

## Function Documentation

## ◆ open_config_file_read()

FILE * open_config_file_read | ( | const char * | path | ) |
| static

Definition at line 40 of file config.c.

Referenced by config_list_service_ids(), config_load_global(), and config_load_service().

Here is the caller graph for this function:

## ◆ copy_cstr_trunc()

void copy_cstr_trunc | ( | char * | dst,
|  | size_t | dst_size,
|  | const char * | src )
| static

Definition at line 62 of file config.c.

Referenced by apply_service_kv().

Here is the caller graph for this function:

## ◆ trim()

void trim | ( | const char * | src,
|  | char * | buf,
|  | size_t | buf_size )
| static

Definition at line 88 of file config.c.

Referenced by config_list_service_ids(), config_load_global(), config_load_service(), and parse_kv().

Here is the caller graph for this function:

## ◆ parse_kv()

int parse_kv | ( | const char * | line,
|  | char * | key_out,
|  | size_t | key_size,
|  | char * | val_out,
|  | size_t | val_size )
| static

Definition at line 122 of file config.c.

References CONFIG_KEY_MAX, and trim().

Referenced by config_load_global(), and config_load_service().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ config_load_global()

int config_load_global | ( | const char * | config_path,
|  | PotrGlobalConfig * | global )

設定ファイルから [global] セクションを読み込みます。

Parameters

  [in] | config_path | 設定ファイルのパス。
  [out] | global | 読み込み結果を格納する構造体へのポインタ。

Returns
  成功時は POTR_SUCCESS、失敗時は POTR_ERROR を返します。

[global] セクションが存在しない場合はデフォルト値を設定します。

Definition at line 160 of file config.c.

References CONFIG_KEY_MAX, CONFIG_LINE_MAX, CONFIG_SECTION_MAX, CONFIG_VAL_MAX, PotrGlobalConfig::health_interval_ms, PotrGlobalConfig::health_timeout_ms, PotrGlobalConfig::max_message_size, PotrGlobalConfig::max_payload, open_config_file_read(), parse_kv(), POTR_DEFAULT_HEALTH_INTERVAL_MS, POTR_DEFAULT_HEALTH_TIMEOUT_MS, POTR_DEFAULT_MAX_PAYLOAD, POTR_DEFAULT_WINDOW_SIZE, POTR_ERROR, POTR_LOG, POTR_MAX_MESSAGE_SIZE, POTR_SEND_QUEUE_DEPTH, POTR_SUCCESS, POTR_TRACE_VERBOSE, PotrGlobalConfig::reorder_timeout_ms, PotrGlobalConfig::send_queue_depth, PotrGlobalConfig::tcp_health_interval_ms, PotrGlobalConfig::tcp_health_timeout_ms, trim(), and PotrGlobalConfig::window_size.

Referenced by potrOpenServiceFromConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ apply_service_kv()

void apply_service_kv | ( | const char * | key,
|  | const char * | val,
|  | PotrServiceDef * | current )
| static

Definition at line 296 of file config.c.

References PotrServiceDef::broadcast_addr, PotrServiceDef::connect_timeout_ms, copy_cstr_trunc(), PotrServiceDef::dst_addr, PotrServiceDef::dst_port, PotrServiceDef::encrypt_enabled, PotrServiceDef::encrypt_key, PotrServiceDef::health_interval_ms, PotrServiceDef::health_timeout_ms, PotrServiceDef::max_peers, PotrServiceDef::multicast_group, PotrServiceDef::pack_wait_ms, POTR_CRYPTO_KEY_SIZE, POTR_LOG, POTR_MAX_ADDR_LEN, potr_passphrase_to_key(), POTR_TRACE_INFO, POTR_TRACE_WARNING, POTR_TYPE_BROADCAST, POTR_TYPE_BROADCAST_RAW, POTR_TYPE_MULTICAST, POTR_TYPE_MULTICAST_RAW, POTR_TYPE_TCP, POTR_TYPE_TCP_BIDIR, POTR_TYPE_UNICAST, POTR_TYPE_UNICAST_BIDIR, POTR_TYPE_UNICAST_BIDIR_N1, POTR_TYPE_UNICAST_RAW, PotrServiceDef::reconnect_interval_ms, PotrServiceDef::service_id, PotrServiceDef::src_addr, PotrServiceDef::src_port, PotrServiceDef::ttl, and PotrServiceDef::type.

Referenced by config_load_service().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ config_load_service()

int config_load_service | ( | const char * | config_path,
|  | int64_t | service_id,
|  | PotrServiceDef * | def )

設定ファイルから指定サービスの定義を読み込みます。

Parameters

  [in] | config_path | 設定ファイルのパス。
  [in] | service_id | 読み込むサービスの ID。
  [out] | def | 読み込み結果を格納する構造体へのポインタ。

Returns
  成功時は POTR_SUCCESS、サービスが見つからない場合は POTR_ERROR を返します。

[service.<id>] 形式のセクション名から <id> 部分を取得し、service_id と照合します。
サービスの識別子はセクション名の <id> であり、ポート番号とは無関係です。

Definition at line 508 of file config.c.

References apply_service_kv(), CONFIG_KEY_MAX, CONFIG_LINE_MAX, CONFIG_SECTION_MAX, CONFIG_VAL_MAX, PotrServiceDef::connect_timeout_ms, PotrServiceDef::dst_addr, PotrServiceDef::dst_port, PotrServiceDef::health_interval_ms, PotrServiceDef::health_timeout_ms, PotrServiceDef::max_peers, open_config_file_read(), PotrServiceDef::pack_wait_ms, parse_kv(), POTR_DEFAULT_CONNECT_TIMEOUT_MS, POTR_DEFAULT_PACK_WAIT_MS, POTR_DEFAULT_RECONNECT_INTERVAL_MS, POTR_DEFAULT_TTL, POTR_ERROR, POTR_LOG, POTR_SUCCESS, POTR_TRACE_VERBOSE, PotrServiceDef::reconnect_interval_ms, PotrServiceDef::service_id, PotrServiceDef::src_addr, PotrServiceDef::src_port, trim(), PotrServiceDef::ttl, and PotrServiceDef::type.

Referenced by potrGetServiceType(), and potrOpenServiceFromConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ config_list_service_ids()

int config_list_service_ids | ( | const char * | config_path,
|  | int64_t ** | ids_out,
|  | int * | count_out )

設定ファイルに登録されているすべてのサービス ID を列挙します。

Parameters

  [in] | config_path | 設定ファイルのパス。
  [out] | ids_out | サービス ID 配列へのポインタを格納する変数。 呼び出し元が free(*ids_out) の責務を持つ。
  [out] | count_out | 列挙したサービス ID 数。

Returns
  成功時は POTR_SUCCESS、失敗時は POTR_ERROR を返します。

初期容量 POTR_MAX_SERVICES で配列を確保し、超過時は realloc で 2 倍に拡張します。

Definition at line 628 of file config.c.

References CONFIG_LINE_MAX, CONFIG_SECTION_MAX, open_config_file_read(), POTR_ERROR, POTR_MAX_SERVICES, POTR_SUCCESS, and trim().

Here is the call graph for this function: