Compare commits

..

1 Commits

Author SHA1 Message Date
OrbisAI Security 94c507c05d
Merge beeb94561e into 3cca66ac15 2026-06-30 08:12:35 +05:30
4 changed files with 26 additions and 47 deletions

View File

@ -1,7 +1,4 @@
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,3 +1,11 @@
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.
@ -6,29 +14,20 @@ 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 = ip1
tracker_server = ip2 tracker_server = ip2
```
```
#include directive to include other ini file #include directive to include other ini file
#@function directive for annotation #@function directive for annotation
#@set directive to set variables for condition of #@if directive #@set directive to set variables for condition of #@if directive
support control statements for special purpose as: support control statements for special purpose as:
#@if, #@else, #@endif, #@for, #@endfor #@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
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.
@ -73,5 +72,5 @@ C function including:
char convert: [char_converter.h] and [char_convert_loader.h] for fast char convert char convert: [char_converter.h] and [char_convert_loader.h] for fast char convert
more detail info please see the c header files. detail info please see the c header files.

View File

@ -37,8 +37,7 @@ 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,11 +299,6 @@ 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;
@ -324,14 +319,12 @@ 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) {
if (strstr(param, ENV_VARIABLE_MARK_STR) == NULL) {
logWarning("file: "__FILE__", line: %d, " logWarning("file: "__FILE__", line: %d, "
"NO set directives before, set value to %s", "NO set directives before, set value to %s",
__LINE__, param); __LINE__, param);
fc_strlcpy(output, param, FAST_INI_ITEM_VALUE_SIZE); fc_strlcpy(output, param, FAST_INI_ITEM_VALUE_SIZE);
return output; return output;
} }
}
pEnd = param + strlen(param); pEnd = param + strlen(param);
pLoopEnd = pEnd - (VARIABLE_TAG_MIN_LENGTH - 1); pLoopEnd = pEnd - (VARIABLE_TAG_MIN_LENGTH - 1);
@ -361,20 +354,11 @@ 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 > ENV_VAR_NAME_STARTWITH_LEN && if (name_len > 0) {
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); value = (char *)fc_hash_find(set->vars, name, name_len);
} else { } else {
value = NULL; value = NULL;
} }
} else {
value = NULL;
}
if (value != NULL) { if (value != NULL) {
len = strlen(value); len = strlen(value);
} }