Compare commits
4 Commits
3cca66ac15
...
369fe740d3
| Author | SHA1 | Date |
|---|---|---|
|
|
369fe740d3 | |
|
|
176cf19576 | |
|
|
598ae419e7 | |
|
|
4f87de79ec |
3
HISTORY
3
HISTORY
|
|
@ -1,4 +1,7 @@
|
|||
|
||||
Version 1.87 2026-07-10
|
||||
* ini_file_readers can refer env variable such as %{env::FASTDFS_IPADDR}
|
||||
|
||||
Version 1.86 2026-06-26
|
||||
* add function fc_parse_version
|
||||
* change return type of format_ip_address and format_ip_port
|
||||
|
|
|
|||
|
|
@ -1,11 +1,3 @@
|
|||
Copyright (C) 2010 Happy Fish / YuQing
|
||||
|
||||
libfastcommon may be copied only under the terms of the Less GNU General
|
||||
Public License(LGPL).
|
||||
Please visit the libfastcommon Home Page for more detail.
|
||||
English language: https://github.com/happyfish100/libfastcommon
|
||||
Chinese language: http://www.fastken.com/
|
||||
|
||||
|
||||
c common functions library extracted from my open source projects FastDFS and
|
||||
FastDHT. this library is very simple and stable.
|
||||
|
|
@ -14,20 +6,29 @@ some functions are wrappered into php extension, such as fastcommon_gethostaddrs
|
|||
fastcommon_id_generator_xxx, fastcommon_get_ifconfigs, fastcommon_get_sysinfo etc.
|
||||
|
||||
C function including:
|
||||
|
||||
logger: [logger.h] asynchronously sync to disk for high performance, thread safe,
|
||||
log rotate, auto delete old log files, compress log file etc.
|
||||
|
||||
ini file reader: [ini_file_reader.h] support sections marked by [SectionName]
|
||||
ini file reader: [ini_file_reader.h] support sections marked by [SectionName],
|
||||
support a config item ocurs multiple times for multiple values, such as:
|
||||
tracker_server = ip1
|
||||
tracker_server = ip2
|
||||
#include directive to include other ini file
|
||||
#@function directive for annotation
|
||||
#@set directive to set variables for condition of #@if directive
|
||||
support control statements for special purpose as:
|
||||
#@if, #@else, #@endif, #@for, #@endfor
|
||||
```
|
||||
tracker_server = ip1
|
||||
tracker_server = ip2
|
||||
```
|
||||
|
||||
id generator: [id_generator.h] generate unique 64 bits integer ID for multi processes
|
||||
```
|
||||
#include directive to include other ini file
|
||||
#@function directive for annotation
|
||||
#@set directive to set variables for condition of #@if directive
|
||||
support control statements for special purpose as:
|
||||
#@if, #@else, #@endif, #@for, #@endfor
|
||||
```
|
||||
|
||||
for more detail, please see [ini file reader guide](doc/ini_file_reader-Chinese.md)
|
||||
|
||||
id generator: [id_generator.h] generate unique 64 bits integer ID for multi processes.
|
||||
for more detail, please see [id generator description](doc/id_generator-Chinese.md)
|
||||
|
||||
string operation: [shared_func.h] uppercase, lowercase, trim etc.
|
||||
|
||||
|
|
@ -37,7 +37,8 @@ libfastcommon是在github开源的⼀个C函数库。它提供了ini⽂件解析
|
|||
[index]表示获取指定序号的本机IP,0表示获取第一个IP,-1表示获取最后一个IP,
|
||||
例如:[0]、inner[-1], outer[1]等等
|
||||
II. SHELL_EXEC 获取命令⾏输出,执行的command为配置项
|
||||
III. REPLACE_VARS 替换配置项中%{VARIABLE}格式的变量,变量由#@set指令设置
|
||||
III. REPLACE_VARS 替换配置项中%{VARIABLE}格式的变量,普通变量由#@set指令设置。
|
||||
可以引用环境变量,格式为 %{env::VARIABLE},例如 %{env::FASTDFS_IPADDR}
|
||||
```
|
||||
|
||||
```
|
||||
|
|
|
|||
|
|
@ -299,6 +299,11 @@ static char *doReplaceVars(IniContext *pContext, const char *param,
|
|||
{
|
||||
#define VARIABLE_TAG_MIN_LENGTH 4 //%{v}
|
||||
|
||||
#define ENV_VAR_NAME_STARTWITH_STR "env::"
|
||||
#define ENV_VAR_NAME_STARTWITH_LEN (sizeof(ENV_VAR_NAME_STARTWITH_STR) - 1)
|
||||
|
||||
#define ENV_VARIABLE_MARK_STR "%{"ENV_VAR_NAME_STARTWITH_STR
|
||||
|
||||
SetDirectiveVars *set;
|
||||
const char *p;
|
||||
const char *e;
|
||||
|
|
@ -319,11 +324,13 @@ static char *doReplaceVars(IniContext *pContext, const char *param,
|
|||
|
||||
set = iniGetVars(pContext);
|
||||
if (set == NULL || set->vars == NULL) {
|
||||
logWarning("file: "__FILE__", line: %d, "
|
||||
"NO set directives before, set value to %s",
|
||||
__LINE__, param);
|
||||
fc_strlcpy(output, param, FAST_INI_ITEM_VALUE_SIZE);
|
||||
return output;
|
||||
if (strstr(param, ENV_VARIABLE_MARK_STR) == NULL) {
|
||||
logWarning("file: "__FILE__", line: %d, "
|
||||
"NO set directives before, set value to %s",
|
||||
__LINE__, param);
|
||||
fc_strlcpy(output, param, FAST_INI_ITEM_VALUE_SIZE);
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
pEnd = param + strlen(param);
|
||||
|
|
@ -354,8 +361,17 @@ static char *doReplaceVars(IniContext *pContext, const char *param,
|
|||
*(name + name_len) = '\0';
|
||||
fc_trim(name);
|
||||
name_len = strlen(name);
|
||||
if (name_len > 0) {
|
||||
value = (char *)fc_hash_find(set->vars, name, name_len);
|
||||
if (name_len > ENV_VAR_NAME_STARTWITH_LEN &&
|
||||
memcmp(name, ENV_VAR_NAME_STARTWITH_STR,
|
||||
ENV_VAR_NAME_STARTWITH_LEN) == 0)
|
||||
{
|
||||
value = getenv(name + ENV_VAR_NAME_STARTWITH_LEN);
|
||||
} else if (name_len > 0) {
|
||||
if (set != NULL && set->vars != NULL) {
|
||||
value = (char *)fc_hash_find(set->vars, name, name_len);
|
||||
} else {
|
||||
value = NULL;
|
||||
}
|
||||
} else {
|
||||
value = NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue