From 0bdb5e4b0384d4e16fd726ca95f0de38219537f8 Mon Sep 17 00:00:00 2001 From: yuqing Date: Mon, 23 Jul 2018 12:48:44 +0800 Subject: [PATCH] ini_file_reader add function iniGetRequiredStrValueEx --- HISTORY | 3 ++- src/Makefile.in | 4 ++-- src/ini_file_reader.c | 35 +++++++++++++++++++++++++++++++++++ src/ini_file_reader.h | 19 +++++++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/HISTORY b/HISTORY index 43e1fb0..67be9a1 100644 --- a/HISTORY +++ b/HISTORY @@ -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 diff --git a/src/Makefile.in b/src/Makefile.in index a778d86..c8b4e61 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -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: diff --git a/src/ini_file_reader.c b/src/ini_file_reader.c index ff31c9e..01c28b1 100644 --- a/src/ini_file_reader.c +++ b/src/ini_file_reader.c @@ -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; +} diff --git a/src/ini_file_reader.h b/src/ini_file_reader.h index c8b5d81..8d8159a 100644 --- a/src/ini_file_reader.h +++ b/src/ini_file_reader.h @@ -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