add functions fc_server_load_from_ini_context etc.
parent
1fd4a5da2b
commit
9d9cee76ac
4
HISTORY
4
HISTORY
|
|
@ -1,4 +1,8 @@
|
|||
|
||||
Version 1.50 2021-04-28
|
||||
* add function is_digital_string
|
||||
* add function fc_server_load_from_ini_context
|
||||
|
||||
Version 1.49 2021-04-17
|
||||
* add macros: FC_ABS and FC_NEGATIVE
|
||||
* uniq_skiplist.c: add uniq_skiplist_pair struct and init function
|
||||
|
|
|
|||
|
|
@ -596,6 +596,13 @@ int iniLoadFromFile(const char *szFilename, IniContext *pContext)
|
|||
NULL, 0, FAST_INI_FLAGS_NONE);
|
||||
}
|
||||
|
||||
int iniLoadFromFile1(const char *szFilename,
|
||||
IniContext *pContext, const char flags)
|
||||
{
|
||||
return iniLoadFromFileEx(szFilename, pContext,
|
||||
FAST_INI_ANNOTATION_WITH_BUILTIN, NULL, 0, flags);
|
||||
}
|
||||
|
||||
static void iniDestroyAnnotations(const int old_annotation_count)
|
||||
{
|
||||
AnnotationEntry *pAnnoEntry;
|
||||
|
|
@ -826,6 +833,11 @@ int iniLoadFromBuffer(char *content, IniContext *pContext)
|
|||
NULL, 0, FAST_INI_FLAGS_NONE);
|
||||
}
|
||||
|
||||
int iniLoadFromBuffer1(char *content, IniContext *pContext, const char flags)
|
||||
{
|
||||
return iniLoadFromBufferEx(content, pContext,
|
||||
FAST_INI_ANNOTATION_WITH_BUILTIN, NULL, 0, flags);
|
||||
}
|
||||
|
||||
typedef int (*init_annotation_func0)(AnnotationEntry *annotation);
|
||||
typedef int (*init_annotation_func1)(AnnotationEntry *annotation,
|
||||
|
|
|
|||
|
|
@ -169,6 +169,16 @@ void iniAnnotationFreeValues(struct ini_annotation_entry *annotation,
|
|||
*/
|
||||
int iniLoadFromFile(const char *szFilename, IniContext *pContext);
|
||||
|
||||
/** load ini items from file with flags
|
||||
* parameters:
|
||||
* szFilename: the filename, can be an URL
|
||||
* pContext: the ini context
|
||||
* flags: the flags
|
||||
* return: error no, 0 for success, != 0 fail
|
||||
*/
|
||||
int iniLoadFromFile1(const char *szFilename,
|
||||
IniContext *pContext, const char flags);
|
||||
|
||||
/** load ini items from file
|
||||
* parameters:
|
||||
* szFilename: the filename, can be an URL
|
||||
|
|
@ -205,6 +215,15 @@ int iniLoadFromBufferEx(char *content, IniContext *pContext,
|
|||
const char annotation_type, AnnotationEntry *annotations, const int count,
|
||||
const char flags);
|
||||
|
||||
/** load ini items from string buffer with flags
|
||||
* parameters:
|
||||
* content: the string buffer to parse
|
||||
* pContext: the ini context
|
||||
* flags: the flags
|
||||
* return: error no, 0 for success, != 0 fail
|
||||
*/
|
||||
int iniLoadFromBuffer1(char *content, IniContext *pContext, const char flags);
|
||||
|
||||
/** free ini context
|
||||
* parameters:
|
||||
* pContext: the ini context
|
||||
|
|
|
|||
|
|
@ -1069,7 +1069,6 @@ static int fc_server_load_one_server(FCServerConfig *ctx,
|
|||
}
|
||||
|
||||
fc_server_set_group_ptr(ctx, server);
|
||||
|
||||
if ((result=fc_server_load_hosts(ctx, server, config_filename,
|
||||
ini_context, section_name)) != 0)
|
||||
{
|
||||
|
|
@ -1085,25 +1084,27 @@ static int fc_server_load_servers(FCServerConfig *ctx,
|
|||
{
|
||||
#define FIXED_SECTION_COUNT 16
|
||||
int result;
|
||||
int count;
|
||||
int section_count;
|
||||
int server_count;
|
||||
IniSectionInfo *sections;
|
||||
IniSectionInfo fixed[FIXED_SECTION_COUNT];
|
||||
IniSectionInfo *section;
|
||||
IniSectionInfo *end;
|
||||
int alloc_bytes;
|
||||
|
||||
count = iniGetSectionCountByPrefix(ini_context, SERVER_SECTION_PREFIX_STR);
|
||||
if (count == 0) {
|
||||
section_count = iniGetSectionCountByPrefix(ini_context,
|
||||
SERVER_SECTION_PREFIX_STR);
|
||||
if (section_count == 0) {
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"config filename: %s, no server section such as [%s$id]",
|
||||
__LINE__, config_filename, SERVER_SECTION_PREFIX_STR);
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
if (count < FIXED_SECTION_COUNT) {
|
||||
if (section_count < FIXED_SECTION_COUNT) {
|
||||
sections = fixed;
|
||||
} else {
|
||||
alloc_bytes = sizeof(IniSectionInfo) * count;
|
||||
alloc_bytes = sizeof(IniSectionInfo) * section_count;
|
||||
sections = (IniSectionInfo *)fc_malloc(alloc_bytes);
|
||||
if (sections == NULL) {
|
||||
return ENOMEM;
|
||||
|
|
@ -1113,7 +1114,7 @@ static int fc_server_load_servers(FCServerConfig *ctx,
|
|||
do {
|
||||
if ((result=iniGetSectionNamesByPrefix(ini_context,
|
||||
SERVER_SECTION_PREFIX_STR, sections,
|
||||
count, &count)) != 0)
|
||||
section_count, §ion_count)) != 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"config filename: %s, get sections by prefix %s fail, "
|
||||
|
|
@ -1122,14 +1123,35 @@ static int fc_server_load_servers(FCServerConfig *ctx,
|
|||
break;
|
||||
}
|
||||
|
||||
if ((result=fc_server_alloc_servers(&ctx->
|
||||
sorted_server_arrays.by_id, count)) != 0)
|
||||
end = sections + section_count;
|
||||
server_count = 0;
|
||||
for (section=sections; section<end; section++) {
|
||||
if (is_digital_string(section->section_name +
|
||||
SERVER_SECTION_PREFIX_LEN))
|
||||
{
|
||||
++server_count;
|
||||
}
|
||||
}
|
||||
if (server_count == 0) {
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"config filename: %s, no server section such as [%s$id]",
|
||||
__LINE__, config_filename, SERVER_SECTION_PREFIX_STR);
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
if ((result=fc_server_alloc_servers(&ctx->sorted_server_arrays.
|
||||
by_id, server_count)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
end = sections + count;
|
||||
for (section=sections; section<end; section++) {
|
||||
if (!is_digital_string(section->section_name +
|
||||
SERVER_SECTION_PREFIX_LEN))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((result=fc_server_load_one_server(ctx, config_filename,
|
||||
ini_context, section->section_name)) != 0)
|
||||
{
|
||||
|
|
@ -1145,8 +1167,8 @@ static int fc_server_load_servers(FCServerConfig *ctx,
|
|||
return result;
|
||||
}
|
||||
|
||||
int fc_server_load_data(FCServerConfig *ctx, IniContext *ini_context,
|
||||
const char *config_filename)
|
||||
static int fc_server_load_data(FCServerConfig *ctx,
|
||||
IniContext *ini_context, const char *config_filename)
|
||||
{
|
||||
int result;
|
||||
|
||||
|
|
@ -1193,8 +1215,7 @@ int fc_server_load_from_file_ex(FCServerConfig *ctx,
|
|||
FC_SERVER_INIT_CONTEXT(ctx, default_port, min_hosts_each_group,
|
||||
share_between_groups);
|
||||
|
||||
if ((result=iniLoadFromFileEx(config_filename, &ini_context,
|
||||
FAST_INI_ANNOTATION_WITH_BUILTIN, NULL, 0,
|
||||
if ((result=iniLoadFromFile1(config_filename, &ini_context,
|
||||
FAST_INI_FLAGS_DISABLE_SAME_SECTION_MERGE)) != 0)
|
||||
{
|
||||
return result;
|
||||
|
|
@ -1214,8 +1235,7 @@ int fc_server_load_from_buffer_ex(FCServerConfig *ctx, char *content,
|
|||
|
||||
FC_SERVER_INIT_CONTEXT(ctx, default_port, min_hosts_each_group,
|
||||
share_between_groups);
|
||||
if ((result=iniLoadFromBufferEx(content, &ini_context,
|
||||
FAST_INI_ANNOTATION_WITH_BUILTIN, NULL, 0,
|
||||
if ((result=iniLoadFromBuffer1(content, &ini_context,
|
||||
FAST_INI_FLAGS_DISABLE_SAME_SECTION_MERGE)) != 0)
|
||||
{
|
||||
return result;
|
||||
|
|
@ -1226,6 +1246,16 @@ int fc_server_load_from_buffer_ex(FCServerConfig *ctx, char *content,
|
|||
return result;
|
||||
}
|
||||
|
||||
int fc_server_load_from_ini_context_ex(FCServerConfig *ctx,
|
||||
IniContext *ini_context, const char *config_filename,
|
||||
const int default_port, const int min_hosts_each_group,
|
||||
const bool share_between_groups)
|
||||
{
|
||||
FC_SERVER_INIT_CONTEXT(ctx, default_port, min_hosts_each_group,
|
||||
share_between_groups);
|
||||
return fc_server_load_data(ctx, ini_context, config_filename);
|
||||
}
|
||||
|
||||
static void fc_server_free_addresses(FCServerConfig *ctx)
|
||||
{
|
||||
FCServerInfo *server;
|
||||
|
|
|
|||
|
|
@ -189,6 +189,22 @@ static inline int fc_server_load_from_buffer(FCServerConfig *ctx,
|
|||
default_port, min_hosts_each_group, share_between_groups);
|
||||
}
|
||||
|
||||
int fc_server_load_from_ini_context_ex(FCServerConfig *ctx,
|
||||
IniContext *ini_context, const char *config_filename,
|
||||
const int default_port, const int min_hosts_each_group,
|
||||
const bool share_between_groups);
|
||||
|
||||
static inline int fc_server_load_from_ini_context(FCServerConfig *ctx,
|
||||
IniContext *ini_context, const char *config_filename)
|
||||
{
|
||||
const int default_port = 0;
|
||||
const int min_hosts_each_group = 1;
|
||||
const bool share_between_groups = false;
|
||||
return fc_server_load_from_ini_context_ex(ctx, ini_context,
|
||||
config_filename, default_port, min_hosts_each_group,
|
||||
share_between_groups);
|
||||
}
|
||||
|
||||
void fc_server_destroy(FCServerConfig *ctx);
|
||||
|
||||
int fc_server_to_config_string(FCServerConfig *ctx, FastBuffer *buffer);
|
||||
|
|
|
|||
|
|
@ -3464,3 +3464,27 @@ int fc_check_filename(const string_t *filename, const char *caption)
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool is_digital_string(const char *str)
|
||||
{
|
||||
const char *p;
|
||||
const char *end;
|
||||
int len;
|
||||
|
||||
len = strlen(str);
|
||||
if (len == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
end = str + len;
|
||||
for (p=str; p<end; p++)
|
||||
{
|
||||
if (!FC_IS_DIGITAL(*p))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1061,6 +1061,13 @@ int fc_check_filename_ex(const string_t *filename, const char *caption,
|
|||
|
||||
int fc_check_filename(const string_t *filename, const char *caption);
|
||||
|
||||
/** is pure digital string
|
||||
* parameters:
|
||||
* str: the string to detect
|
||||
* return: true for digital string, otherwise false
|
||||
*/
|
||||
bool is_digital_string(const char *str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue