use macros: IS_URL_RESOURCE and IS_FILE_RESOURCE
parent
639d388c6d
commit
ec181d51cf
|
|
@ -647,7 +647,7 @@ int iniLoadFromFileEx(const char *szFilename, IniContext *pContext,
|
||||||
int result;
|
int result;
|
||||||
int len;
|
int len;
|
||||||
char *pLast;
|
char *pLast;
|
||||||
char full_filename[MAX_PATH_SIZE];
|
char full_filename[PATH_MAX];
|
||||||
int old_annotation_count;
|
int old_annotation_count;
|
||||||
|
|
||||||
if ((result=iniInitContext(pContext, annotation_type,
|
if ((result=iniInitContext(pContext, annotation_type,
|
||||||
|
|
@ -656,13 +656,18 @@ int iniLoadFromFileEx(const char *szFilename, IniContext *pContext,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncasecmp(szFilename, "http://", 7) == 0)
|
if (IS_URL_RESOURCE(szFilename))
|
||||||
{
|
{
|
||||||
*pContext->config_path = '\0';
|
*pContext->config_path = '\0';
|
||||||
snprintf(full_filename, sizeof(full_filename),"%s",szFilename);
|
snprintf(full_filename, sizeof(full_filename), "%s", szFilename);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (IS_FILE_RESOURCE(szFilename))
|
||||||
|
{
|
||||||
|
szFilename += FILE_RESOURCE_TAG_LEN;
|
||||||
|
}
|
||||||
|
|
||||||
if (*szFilename == '/')
|
if (*szFilename == '/')
|
||||||
{
|
{
|
||||||
pLast = strrchr(szFilename, '/');
|
pLast = strrchr(szFilename, '/');
|
||||||
|
|
@ -758,7 +763,7 @@ static int iniDoLoadFromFile(const char *szFilename, \
|
||||||
int64_t file_size;
|
int64_t file_size;
|
||||||
char error_info[512];
|
char error_info[512];
|
||||||
|
|
||||||
if (strncasecmp(szFilename, "http://", 7) == 0)
|
if (IS_URL_RESOURCE(szFilename))
|
||||||
{
|
{
|
||||||
if ((result=get_url_content(szFilename, 10, 60, &http_status, \
|
if ((result=get_url_content(szFilename, 10, 60, &http_status, \
|
||||||
&content, &content_len, error_info)) != 0)
|
&content, &content_len, error_info)) != 0)
|
||||||
|
|
@ -972,10 +977,11 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
|
||||||
char *pEqualChar;
|
char *pEqualChar;
|
||||||
char pItemName[FAST_INI_ITEM_NAME_LEN + 1];
|
char pItemName[FAST_INI_ITEM_NAME_LEN + 1];
|
||||||
char *pAnnoItemLine;
|
char *pAnnoItemLine;
|
||||||
char *pIncludeFilename;
|
char pIncludeFilename[PATH_MAX];
|
||||||
|
char *pTrueFilename;
|
||||||
char *pItemValues[100];
|
char *pItemValues[100];
|
||||||
char pFuncName[FAST_INI_ITEM_NAME_LEN + 1];
|
char pFuncName[FAST_INI_ITEM_NAME_LEN + 1];
|
||||||
char full_filename[MAX_PATH_SIZE];
|
char full_filename[PATH_MAX];
|
||||||
int i;
|
int i;
|
||||||
int nLineLen;
|
int nLineLen;
|
||||||
int nNameLen;
|
int nNameLen;
|
||||||
|
|
@ -1014,31 +1020,35 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
|
||||||
strncasecmp(pLine+1, "include", 7) == 0 && \
|
strncasecmp(pLine+1, "include", 7) == 0 && \
|
||||||
(*(pLine+8) == ' ' || *(pLine+8) == '\t'))
|
(*(pLine+8) == ' ' || *(pLine+8) == '\t'))
|
||||||
{
|
{
|
||||||
pIncludeFilename = fc_strdup(pLine + 9);
|
snprintf(pIncludeFilename, sizeof(pIncludeFilename),
|
||||||
if (pIncludeFilename == NULL)
|
"%s", pLine + 9);
|
||||||
{
|
|
||||||
result = ENOMEM;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
STR_TRIM(pIncludeFilename);
|
STR_TRIM(pIncludeFilename);
|
||||||
if (strncasecmp(pIncludeFilename, "http://", 7) == 0)
|
if (IS_URL_RESOURCE(pIncludeFilename))
|
||||||
{
|
{
|
||||||
snprintf(full_filename, sizeof(full_filename),\
|
snprintf(full_filename, sizeof(full_filename),
|
||||||
"%s", pIncludeFilename);
|
"%s", pIncludeFilename);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (*pIncludeFilename == '/')
|
if (IS_FILE_RESOURCE(pIncludeFilename))
|
||||||
|
{
|
||||||
|
pTrueFilename = pIncludeFilename + FILE_RESOURCE_TAG_LEN;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pTrueFilename = pIncludeFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*pTrueFilename == '/')
|
||||||
{
|
{
|
||||||
snprintf(full_filename, sizeof(full_filename), \
|
snprintf(full_filename, sizeof(full_filename), \
|
||||||
"%s", pIncludeFilename);
|
"%s", pTrueFilename);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
snprintf(full_filename, sizeof(full_filename), \
|
snprintf(full_filename, sizeof(full_filename), \
|
||||||
"%s/%s", pContext->config_path, \
|
"%s/%s", pContext->config_path, \
|
||||||
pIncludeFilename);
|
pTrueFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fileExists(full_filename))
|
if (!fileExists(full_filename))
|
||||||
|
|
@ -1046,8 +1056,7 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
"include file \"%s\" not exists, " \
|
"include file \"%s\" not exists, " \
|
||||||
"line: \"%s\"", __LINE__, \
|
"line: \"%s\"", __LINE__, \
|
||||||
pIncludeFilename, pLine);
|
pTrueFilename, pLine);
|
||||||
free(pIncludeFilename);
|
|
||||||
result = ENOENT;
|
result = ENOENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1057,7 +1066,6 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
|
||||||
result = iniDoLoadFromFile(full_filename, pContext);
|
result = iniDoLoadFromFile(full_filename, pContext);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
free(pIncludeFilename);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1065,7 +1073,6 @@ static int iniDoLoadItemsFromBuffer(char *content, IniContext *pContext)
|
||||||
pSection = pContext->current_section;
|
pSection = pContext->current_section;
|
||||||
pItem = pSection->items + pSection->count; //must re-asign
|
pItem = pSection->items + pSection->count; //must re-asign
|
||||||
|
|
||||||
free(pIncludeFilename);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (*pLine == '#')
|
else if (*pLine == '#')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue