Compare commits

..

4 Commits

Author SHA1 Message Date
YuQing 369fe740d3 README.md: beautify layout 2026-07-10 20:45:30 +08:00
YuQing 176cf19576 rename README to README.md 2026-07-10 20:39:34 +08:00
YuQing 598ae419e7 README add doc links 2026-07-10 20:34:54 +08:00
YuQing 4f87de79ec ini_file_readers can refer env variable as %{env::XXX} 2026-07-10 19:45:08 +08:00
4 changed files with 46 additions and 25 deletions

View File

@ -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 Version 1.86 2026-06-26
* add function fc_parse_version * add function fc_parse_version
* change return type of format_ip_address and format_ip_port * change return type of format_ip_address and format_ip_port

View File

@ -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 c common functions library extracted from my open source projects FastDFS and
FastDHT. this library is very simple and stable. 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. fastcommon_id_generator_xxx, fastcommon_get_ifconfigs, fastcommon_get_sysinfo etc.
C function including: C function including:
logger: [logger.h] asynchronously sync to disk for high performance, thread safe, logger: [logger.h] asynchronously sync to disk for high performance, thread safe,
log rotate, auto delete old log files, compress log file etc. 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: support a config item ocurs multiple times for multiple values, such as:
tracker_server = ip1 ```
tracker_server = ip2 tracker_server = ip1
#include directive to include other ini file tracker_server = ip2
#@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
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. string operation: [shared_func.h] uppercase, lowercase, trim etc.

View File

@ -37,7 +37,8 @@ libfastcommon是在github开源的⼀个C函数库。它提供了ini⽂件解析
[index]表示获取指定序号的本机IP0表示获取第一个IP-1表示获取最后一个IP [index]表示获取指定序号的本机IP0表示获取第一个IP-1表示获取最后一个IP
例如:[0]、inner[-1], outer[1]等等 例如:[0]、inner[-1], outer[1]等等
II. SHELL_EXEC 获取命令⾏输出执行的command为配置项 II. SHELL_EXEC 获取命令⾏输出执行的command为配置项
III. REPLACE_VARS 替换配置项中%{VARIABLE}格式的变量,变量由#@set指令设置 III. REPLACE_VARS 替换配置项中%{VARIABLE}格式的变量,普通变量由#@set指令设置。
可以引用环境变量,格式为 %{env::VARIABLE},例如 %{env::FASTDFS_IPADDR}
``` ```
``` ```

View File

@ -299,6 +299,11 @@ static char *doReplaceVars(IniContext *pContext, const char *param,
{ {
#define VARIABLE_TAG_MIN_LENGTH 4 //%{v} #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; SetDirectiveVars *set;
const char *p; const char *p;
const char *e; const char *e;
@ -319,11 +324,13 @@ static char *doReplaceVars(IniContext *pContext, const char *param,
set = iniGetVars(pContext); set = iniGetVars(pContext);
if (set == NULL || set->vars == NULL) { if (set == NULL || set->vars == NULL) {
logWarning("file: "__FILE__", line: %d, " if (strstr(param, ENV_VARIABLE_MARK_STR) == NULL) {
"NO set directives before, set value to %s", logWarning("file: "__FILE__", line: %d, "
__LINE__, param); "NO set directives before, set value to %s",
fc_strlcpy(output, param, FAST_INI_ITEM_VALUE_SIZE); __LINE__, param);
return output; fc_strlcpy(output, param, FAST_INI_ITEM_VALUE_SIZE);
return output;
}
} }
pEnd = param + strlen(param); pEnd = param + strlen(param);
@ -354,8 +361,17 @@ static char *doReplaceVars(IniContext *pContext, const char *param,
*(name + name_len) = '\0'; *(name + name_len) = '\0';
fc_trim(name); fc_trim(name);
name_len = strlen(name); name_len = strlen(name);
if (name_len > 0) { if (name_len > ENV_VAR_NAME_STARTWITH_LEN &&
value = (char *)fc_hash_find(set->vars, name, name_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 { } else {
value = NULL; value = NULL;
} }