Skip to content

Commit 24a72f6

Browse files
committed
add INI config file support via libinih #153
- introduce --conf option to load runtime settings from INI - enforce precedence: defaults < config file < CLI arguments Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
1 parent 1921000 commit 24a72f6

File tree

6 files changed

+460
-36
lines changed

6 files changed

+460
-36
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
name: ${{ matrix.name }}
3232
pkg: ${{ matrix.pkg }}
3333
run: |
34-
sudo apt install -y libev-dev
34+
sudo apt install -y libev-dev libinih-dev
3535
[ -n "$pkg" ] && sudo apt install -y $pkg
3636
[ "$name" = "none" ] && cmake . -DSSL_SUPPORT=OFF || cmake . -DUSE_$name=ON
3737
make

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Trusted by leading technology companies:
128128
### C Client Dependencies
129129
- **Required:**
130130
- [libev] - High-performance event loop library
131+
- [inih](https://github.com/benhoyt/inih) - Lightweight INI parser for loading rtty config file
131132
- **Optional (for SSL support):**
132133
- [mbedtls(polarssl)] - Lightweight SSL/TLS library
133134
- [CyaSSl(wolfssl)] - Embedded SSL/TLS library

README_ZH.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ rtty 非常适合远程维护和管理大规模分布式Linux设备,是企业
126126
### C 语言客户端依赖
127127
- **必需组件**
128128
- [libev] - 高性能事件循环库
129+
- [inih](https://github.com/benhoyt/inih) - 轻量级 INI 解析库,用于加载 rtty 配置文件
129130
- **可选组件(SSL支持)**
130131
- [mbedtls(polarssl)] - 轻量级SSL/TLS库
131132
- [CyaSSl(wolfssl)] - 嵌入式SSL/TLS库

rtty.ini

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; rtty configuration example
2+
; Priority: defaults < config file < command line
3+
4+
[rtty]
5+
id = device-001
6+
group = default
7+
host = 127.0.0.1
8+
port = 5912
9+
heartbeat = 30
10+
http-timeout = 30
11+
description = edge gateway in room A
12+
token = your-token
13+
username = root
14+
reconnect = true
15+
verbose = false
16+
background = false
17+
18+
[ssl]
19+
enabled = false
20+
insecure = false
21+
; cacert = /etc/ssl/certs/ca-certificates.crt
22+
; cert = /etc/rtty/client.crt
23+
; key = /etc/rtty/client.key

src/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@ set(RTTY_VERSION_MAJOR 9)
33
set(RTTY_VERSION_MINOR 0)
44
set(RTTY_VERSION_PATCH 4)
55

6+
include(FindPkgConfig)
7+
68
# Check the third party Libraries
79
find_package(Libev REQUIRED)
810

11+
pkg_search_module(LIBINIH inih)
12+
if (NOT LIBINIH_FOUND)
13+
message(FATAL_ERROR "libinih is required.")
14+
endif()
15+
916
aux_source_directory(. SRCS)
1017
aux_source_directory(log SRCS)
1118
aux_source_directory(buffer SRCS)
1219

1320
add_executable(rtty ${SRCS})
1421
target_compile_definitions(rtty PRIVATE _GNU_SOURCE)
1522
target_compile_options(rtty PRIVATE -O -Wall -Werror --std=gnu99)
16-
target_include_directories(rtty PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/buffer ${LIBEV_INCLUDE_DIR})
17-
target_link_libraries(rtty PRIVATE ${LIBEV_LIBRARY} util crypt m)
23+
target_include_directories(rtty PRIVATE
24+
${CMAKE_CURRENT_BINARY_DIR}
25+
${CMAKE_CURRENT_SOURCE_DIR}/buffer
26+
${LIBEV_INCLUDE_DIR}
27+
${LIBINIH_INCLUDE_DIRS}
28+
)
29+
target_link_libraries(rtty PRIVATE ${LIBEV_LIBRARY} ${LIBINIH_LIBRARIES} util crypt m)
1830

1931
add_subdirectory(ssl)
2032

0 commit comments

Comments
 (0)