ini_file_reader add function iniGetRequiredStrValueEx

pull/37/head
yuqing 2018-07-23 12:48:44 +08:00
parent edced2173b
commit 0bdb5e4b03
4 changed files with 58 additions and 3 deletions

View File

@ -1,10 +1,11 @@
Version 1.39 2018-07-19
Version 1.39 2018-07-23
* add #@function REPLACE_VARS
* #@set value can embed %{VARIABLE}
* shared_func.h: add function starts_with and ends_with
* common_blocked_queue.h: add function common_blocked_queue_try_pop
* sched_thread.c: fix first schedule time
* ini_file_reader add function iniGetRequiredStrValueEx
Version 1.38 2018-06-26
* connection_pool.c: set err_no to 0 when success

View File

@ -47,8 +47,8 @@ STATIC_LIBS = libfastcommon.a
ALL_LIBS = $(SHARED_LIBS) $(STATIC_LIBS)
all: $(ALL_OBJS) $(ALL_PRGS) $(ALL_LIBS)
libfastcommon.so:
$(COMPILE) -o $@ $< -shared $(FAST_SHARED_OBJS) $(LIB_PATH)
libfastcommon.so: $(FAST_SHARED_OBJS)
$(COMPILE) -o $@ -shared $(FAST_SHARED_OBJS) $(LIB_PATH)
libfastcommon.a: $(FAST_STATIC_OBJS)
ar rcs $@ $(FAST_STATIC_OBJS)
.o:

View File

@ -2839,4 +2839,39 @@ IniItem *iniGetSectionItems(const char *szSectionName, IniContext *pContext,
return pSection->items;
}
char *iniGetRequiredStrValueEx(const char *szSectionName, const char *szItemName,
IniContext *pContext, const int nMinLength)
{
char *value;
value = iniGetStrValue(szSectionName, szItemName, pContext);
if (value == NULL)
{
logError("file: "__FILE__", line: %d, "
"item: %s not exist", __LINE__, szItemName);
return NULL;
}
if (nMinLength > 0)
{
if (nMinLength == 1 && *value == '\0')
{
logError("file: "__FILE__", line: %d, "
"item: %s, value is empty", __LINE__, szItemName);
return NULL;
}
else
{
int len;
len = strlen(value);
if (len < nMinLength)
{
logError("file: "__FILE__", line: %d, "
"item: %s, value length: %d < min length: %d",
__LINE__, szItemName, len, nMinLength);
return NULL;
}
}
}
return value;
}

View File

@ -265,6 +265,25 @@ static inline IniItem *iniGetGlobalItems(IniContext *pContext, int *nCount)
IniItem *iniGetSectionItems(const char *szSectionName, IniContext *pContext,
int *nCount);
/** get item string value
* parameters:
* szSectionName: the section name, NULL or empty string for
* global section
* szItemName: the item name
* pContext: the ini context
* nMinLength: the min value length
* return: item value, return NULL when the item not exist
*/
char *iniGetRequiredStrValueEx(const char *szSectionName, const char *szItemName,
IniContext *pContext, const int nMinLength);
static inline char *iniGetRequiredStrValue(const char *szSectionName,
const char *szItemName, IniContext *pContext)
{
const int nMinLength = 1;
return iniGetRequiredStrValueEx(szSectionName, szItemName, pContext, nMinLength);
}
#ifdef __cplusplus
}
#endif