From 5b9f98ee20a245cd5245717b168d7428c6bdad31 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 7 Sep 2007 08:56:43 +0000 Subject: - added eCmdHdlrGetWord command handler - added $ModDir config directive --- cfsysline.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'cfsysline.c') diff --git a/cfsysline.c b/cfsysline.c index b17683c6..24e652d7 100644 --- a/cfsysline.c +++ b/cfsysline.c @@ -348,6 +348,58 @@ finalize_it: } +/* Parse and a word config line option. A word is a consequitive + * sequence of non-whitespace characters. pVal must be + * a pointer to a string which is to receive the option + * value. The returned string must be freed by the caller. + * rgerhards, 2007-09-07 + */ +static rsRetVal doGetWord(uchar **pp, rsRetVal (*pSetHdlr)(void*, uchar*), void *pVal) +{ + DEFiRet; + rsCStrObj *pStrB; + uchar *p; + uchar *pNewVal; + + assert(pp != NULL); + assert(*pp != NULL); + + if((pStrB = rsCStrConstruct()) == NULL) + return RS_RET_OUT_OF_MEMORY; + + /* parse out the word */ + p = *pp; + + while(*p && !isspace((int) *p)) { + CHKiRet(rsCStrAppendChar(pStrB, *p++)); + } + CHKiRet(rsCStrFinish(pStrB)); + + CHKiRet(rsCStrConvSzStrAndDestruct(pStrB, &pNewVal, 0)); +dbgprintf("pNewVal: %s\n", pNewVal); + + /* we got the word, now set it */ + if(pSetHdlr == NULL) { + /* we should set value directly to var */ + *((uchar**)pVal) = pNewVal; + } else { + /* we set value via a set function */ + CHKiRet(pSetHdlr(pVal, pNewVal)); + } + + *pp = p; + skipWhiteSpace(pp); /* skip over any whitespace */ + +finalize_it: + if(iRet != RS_RET_OK) { + if(pStrB != NULL) + rsCStrDestruct(pStrB); + } + + return iRet; +} + + /* --------------- END functions for handling canned syntaxes --------------- */ /* destructor for cslCmdHdlr @@ -426,6 +478,9 @@ static rsRetVal cslchCallHdlr(cslCmdHdlr_t *pThis, uchar **ppConfLine) case eCmdHdlrGetChar: pHdlr = doGetChar; break; + case eCmdHdlrGetWord: + pHdlr = doGetWord; + break; default: iRet = RS_RET_NOT_IMPLEMENTED; goto finalize_it; -- cgit