ignore annotation in some cases
parent
29451eaf49
commit
5f52349bd6
|
|
@ -230,6 +230,107 @@ int iniLoadFromFile(const char *szFilename, IniContext *pContext)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int iniLoadFromFileEx(const char *szFilename, IniContext *pContext,
|
||||||
|
char annotation)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
int len;
|
||||||
|
char *pLast;
|
||||||
|
char full_filename[MAX_PATH_SIZE];
|
||||||
|
|
||||||
|
if ((result=iniInitContext(pContext)) != 0)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
pContext->annotation = annotation;
|
||||||
|
|
||||||
|
if (strncasecmp(szFilename, "http://", 7) == 0)
|
||||||
|
{
|
||||||
|
*pContext->config_path = '\0';
|
||||||
|
snprintf(full_filename, sizeof(full_filename),"%s",szFilename);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (*szFilename == '/')
|
||||||
|
{
|
||||||
|
pLast = strrchr(szFilename, '/');
|
||||||
|
len = pLast - szFilename;
|
||||||
|
if (len >= sizeof(pContext->config_path))
|
||||||
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "\
|
||||||
|
"the path of the config file: %s is " \
|
||||||
|
"too long!", __LINE__, szFilename);
|
||||||
|
return ENOSPC;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(pContext->config_path, szFilename, len);
|
||||||
|
*(pContext->config_path + len) = '\0';
|
||||||
|
snprintf(full_filename, sizeof(full_filename), \
|
||||||
|
"%s", szFilename);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memset(pContext->config_path, 0, \
|
||||||
|
sizeof(pContext->config_path));
|
||||||
|
if (getcwd(pContext->config_path, sizeof( \
|
||||||
|
pContext->config_path)) == NULL)
|
||||||
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, " \
|
||||||
|
"getcwd fail, errno: %d, " \
|
||||||
|
"error info: %s", \
|
||||||
|
__LINE__, errno, STRERROR(errno));
|
||||||
|
return errno != 0 ? errno : EPERM;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = strlen(pContext->config_path);
|
||||||
|
if (len > 0 && pContext->config_path[len - 1] == '/')
|
||||||
|
{
|
||||||
|
len--;
|
||||||
|
*(pContext->config_path + len) = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(full_filename, sizeof(full_filename), \
|
||||||
|
"%s/%s", pContext->config_path, szFilename);
|
||||||
|
|
||||||
|
pLast = strrchr(szFilename, '/');
|
||||||
|
if (pLast != NULL)
|
||||||
|
{
|
||||||
|
int tail_len;
|
||||||
|
|
||||||
|
tail_len = pLast - szFilename;
|
||||||
|
if (len + 1 + tail_len >= sizeof( \
|
||||||
|
pContext->config_path))
|
||||||
|
{
|
||||||
|
logError("file: "__FILE__", line: %d, "\
|
||||||
|
"the path of the config " \
|
||||||
|
"file: %s is too long!", \
|
||||||
|
__LINE__, szFilename);
|
||||||
|
return ENOSPC;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(pContext->config_path + len++) = '/';
|
||||||
|
memcpy(pContext->config_path + len, \
|
||||||
|
szFilename, tail_len);
|
||||||
|
len += tail_len;
|
||||||
|
*(pContext->config_path + len) = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = iniDoLoadFromFile(full_filename, pContext);
|
||||||
|
if (result == 0)
|
||||||
|
{
|
||||||
|
iniSortItems(pContext);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iniFreeContext(pContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static int iniDoLoadFromFile(const char *szFilename, \
|
static int iniDoLoadFromFile(const char *szFilename, \
|
||||||
IniContext *pContext)
|
IniContext *pContext)
|
||||||
{
|
{
|
||||||
|
|
@ -410,26 +511,28 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
|
||||||
strncasecmp(pLine+1, "@function", 9) == 0 && \
|
strncasecmp(pLine+1, "@function", 9) == 0 && \
|
||||||
(*(pLine+10) == ' ' || *(pLine+10) == '\t')))
|
(*(pLine+10) == ' ' || *(pLine+10) == '\t')))
|
||||||
{
|
{
|
||||||
nNameLen = strlen(pLine + 11);
|
if (pContext->annotation != IGNORE_ANNOTATION) {
|
||||||
if (nNameLen > FAST_INI_ITEM_NAME_LEN)
|
nNameLen = strlen(pLine + 11);
|
||||||
{
|
if (nNameLen > FAST_INI_ITEM_NAME_LEN)
|
||||||
nNameLen = FAST_INI_ITEM_NAME_LEN;
|
{
|
||||||
|
nNameLen = FAST_INI_ITEM_NAME_LEN;
|
||||||
|
}
|
||||||
|
memcpy(pFuncName, pLine + 11, nNameLen);
|
||||||
|
pFuncName[nNameLen] = '\0';
|
||||||
|
trim(pFuncName);
|
||||||
|
if ((int)strlen(pFuncName) > 0)
|
||||||
|
{
|
||||||
|
isAnnotation = 1;
|
||||||
|
pAnnoItemLine = pLastEnd + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logWarning("file: "__FILE__", line: %d, " \
|
||||||
|
"the function name of annotation line is empty", \
|
||||||
|
__LINE__);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
memcpy(pFuncName, pLine + 11, nNameLen);
|
|
||||||
pFuncName[nNameLen] = '\0';
|
|
||||||
trim(pFuncName);
|
|
||||||
if ((int)strlen(pFuncName) > 0)
|
|
||||||
{
|
|
||||||
isAnnotation = 1;
|
|
||||||
pAnnoItemLine = pLastEnd + 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logWarning("file: "__FILE__", line: %d, " \
|
|
||||||
"the function name of annotation line is empty", \
|
|
||||||
__LINE__);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trim(pLine);
|
trim(pLine);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@
|
||||||
#define FAST_INI_ITEM_NAME_LEN 64
|
#define FAST_INI_ITEM_NAME_LEN 64
|
||||||
#define FAST_INI_ITEM_VALUE_LEN 256
|
#define FAST_INI_ITEM_VALUE_LEN 256
|
||||||
|
|
||||||
|
#define IGNORE_ANNOTATION 1
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *func_name;
|
char *func_name;
|
||||||
int (*func_init) ();
|
int (*func_init) ();
|
||||||
|
|
@ -45,6 +47,7 @@ typedef struct
|
||||||
HashArray sections; //key is session name, and value is IniSection
|
HashArray sections; //key is session name, and value is IniSection
|
||||||
IniSection *current_section; //for load from ini file
|
IniSection *current_section; //for load from ini file
|
||||||
char config_path[MAX_PATH_SIZE]; //save the config filepath
|
char config_path[MAX_PATH_SIZE]; //save the config filepath
|
||||||
|
char annotation;
|
||||||
} IniContext;
|
} IniContext;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
@ -62,6 +65,16 @@ void iniDestroyAnnotationCallBack();
|
||||||
*/
|
*/
|
||||||
int iniLoadFromFile(const char *szFilename, IniContext *pContext);
|
int iniLoadFromFile(const char *szFilename, IniContext *pContext);
|
||||||
|
|
||||||
|
/** load ini items from file
|
||||||
|
* parameters:
|
||||||
|
* szFilename: the filename, can be an URL
|
||||||
|
* pContext: the ini context
|
||||||
|
* annotation: whether ignore annotation
|
||||||
|
* return: error no, 0 for success, != 0 fail
|
||||||
|
*/
|
||||||
|
int iniLoadFromFileEx(const char *szFilename, IniContext *pContext,
|
||||||
|
char annotation);
|
||||||
|
|
||||||
/** load ini items from string buffer
|
/** load ini items from string buffer
|
||||||
* parameters:
|
* parameters:
|
||||||
* content: the string buffer to parse
|
* content: the string buffer to parse
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,8 @@ int get_base_path_from_conf_file(const char *filename, char *base_path,
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
memset(&iniContext, 0, sizeof(IniContext));
|
memset(&iniContext, 0, sizeof(IniContext));
|
||||||
if ((result=iniLoadFromFile(filename, &iniContext)) != 0)
|
|
||||||
|
if ((result=iniLoadFromFileEx(filename, &iniContext, IGNORE_ANNOTATION)) != 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
"load conf file \"%s\" fail, ret code: %d", \
|
"load conf file \"%s\" fail, ret code: %d", \
|
||||||
|
|
|
||||||
|
|
@ -1322,7 +1322,7 @@ int load_log_level_ex(const char *conf_filename)
|
||||||
int result;
|
int result;
|
||||||
IniContext iniContext;
|
IniContext iniContext;
|
||||||
|
|
||||||
if ((result=iniLoadFromFile(conf_filename, &iniContext)) != 0)
|
if ((result=iniLoadFromFileEx(conf_filename, &iniContext, IGNORE_ANNOTATION)) != 0)
|
||||||
{
|
{
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
"load conf file \"%s\" fail, ret code: %d", \
|
"load conf file \"%s\" fail, ret code: %d", \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue