openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/rsyslog/8.1903.0-r0/rsyslog-8.1903.0/runtime/parser.c
static rsRetVal ParseMsg(smsg_t* pMsg)
{
    rsRetVal localRet = RS_RET_ERR;
    parserList_t* pParserList;
    parser_t* pParser;
    sbool bIsSanitized;
    sbool bPRIisParsed;
    static int iErrMsgRateLimiter = 0;
    DEFiRet;

    if (pMsg->iLenRawMsg == 0)
        ABORT_FINALIZE(RS_RET_EMPTY_MSG);

    CHKiRet(uncompressMessage(pMsg));

    /* we take the risk to print a non-sanitized string, because this is the
     * best we can get (and that functionality is too important for debugging to
     * drop it...).
     */
    DBGPRINTF("msg parser: flags %x, from '%s', msg '%.60s'\n", pMsg->msgFlags,
              (pMsg->msgFlags & NEEDS_DNSRESOL)
                  ? UCHAR_CONSTANT("~NOTRESOLVED~")
                  : getRcvFrom(pMsg),
              pMsg->pszRawMsg);

    /* we now need to go through our list of parsers and see which one is
     * capable of parsing the message. Note that the first parser that requires
     * message sanitization will cause it to happen. After that, access to the
     * unsanitized message is no loger possible.
     */
    pParserList = ruleset.GetParserList(ourConf, pMsg);
    if (pParserList == NULL)
    {
        pParserList = pDfltParsLst;
    }
    DBGPRINTF("parse using parser list %p%s.\n", pParserList,
              (pParserList == pDfltParsLst) ? " (the default list)" : "");

    bIsSanitized = RSFALSE;
    bPRIisParsed = RSFALSE;
    while (pParserList != NULL)
    {
        pParser = pParserList->pParser;
        if (pParser->bDoSanitazion && bIsSanitized == RSFALSE)
        {
            CHKiRet(SanitizeMsg(pMsg));
            if (pParser->bDoPRIParsing && bPRIisParsed == RSFALSE)
            {
                CHKiRet(ParsePRI(pMsg));
                bPRIisParsed = RSTRUE;
            }
            bIsSanitized = RSTRUE;
        }
        if (pParser->pModule->mod.pm.parse2 == NULL)
            localRet = pParser->pModule->mod.pm.parse(pMsg);
        else
            localRet = pParser->pModule->mod.pm.parse2(pParser->pInst, pMsg);
        DBGPRINTF("Parser '%s' returned %d\n", pParser->pName, localRet);
        if (localRet != RS_RET_COULD_NOT_PARSE)
            break;
        pParserList = pParserList->pNext;
    }

    /* We need to log a warning message and drop the message if we did not find
     * a parser. Note that we log at most the first 1000 message, as this may
     * very well be a problem that causes a message generation loop. We do not
     * synchronize that counter, it doesn't matter if we log a handful messages
     * more than we should...
     */
    if (localRet != RS_RET_OK)
    {
        if (++iErrMsgRateLimiter < 1000)
        {
            LogError(0, localRet,
                     "Error: one message could not be processed by "
                     "any parser, message is being discarded (start of raw "
                     "msg: '%.60s')",
                     pMsg->pszRawMsg);
        }
        DBGPRINTF("No parser could process the message (state %d), we need to "
                  "discard it.\n",
                  localRet);
        ABORT_FINALIZE(localRet);
    }

    /* "finalize" message object */
    pMsg->msgFlags &= ~NEEDS_PARSING; /* this message is now parsed */

finalize_it:
    RETiRet;
}
/* Parse a received message. The object's rawmsg property is taken and
 * parsed according to the relevant standards. This can later be
 * extended to support configured parsers.
 * rgerhards, 2008-10-09
 */
Parse a received message. The object's rawmsg property is taken and
parsed according to the relevant standards. This can later be
extended to support configured parsers.
Parse a received message . The object ' s rawmsg property is taken and parsed according to the relevant standards . This can later be extended to support configured parsers .
static rsRetVal ParseMsg(smsg_t* pMsg)
{
    rsRetVal localRet = RS_RET_ERR;
    parserList_t* pParserList;
    parser_t* pParser;
    sbool bIsSanitized;
    sbool bPRIisParsed;
    static int iErrMsgRateLimiter = 0;
    DEFiRet;
    if (pMsg->iLenRawMsg == 0)
        ABORT_FINALIZE(RS_RET_EMPTY_MSG);
    CHKiRet(uncompressMessage(pMsg));
    DBGPRINTF("msg parser: flags %x, from '%s', msg '%.60s'\n", pMsg->msgFlags,
              (pMsg->msgFlags & NEEDS_DNSRESOL)
                  ? UCHAR_CONSTANT("~NOTRESOLVED~")
                  : getRcvFrom(pMsg),
              pMsg->pszRawMsg);
    pParserList = ruleset.GetParserList(ourConf, pMsg);
    if (pParserList == NULL)
    {
        pParserList = pDfltParsLst;
    }
    DBGPRINTF("parse using parser list %p%s.\n", pParserList,
              (pParserList == pDfltParsLst) ? " (the default list)" : "");
    bIsSanitized = RSFALSE;
    bPRIisParsed = RSFALSE;
    while (pParserList != NULL)
    {
        pParser = pParserList->pParser;
        if (pParser->bDoSanitazion && bIsSanitized == RSFALSE)
        {
            CHKiRet(SanitizeMsg(pMsg));
            if (pParser->bDoPRIParsing && bPRIisParsed == RSFALSE)
            {
                CHKiRet(ParsePRI(pMsg));
                bPRIisParsed = RSTRUE;
            }
            bIsSanitized = RSTRUE;
        }
        if (pParser->pModule->mod.pm.parse2 == NULL)
            localRet = pParser->pModule->mod.pm.parse(pMsg);
        else
            localRet = pParser->pModule->mod.pm.parse2(pParser->pInst, pMsg);
        DBGPRINTF("Parser '%s' returned %d\n", pParser->pName, localRet);
        if (localRet != RS_RET_COULD_NOT_PARSE)
            break;
        pParserList = pParserList->pNext;
    }
    if (localRet != RS_RET_OK)
    {
        if (++iErrMsgRateLimiter < 1000)
        {
            LogError(0, localRet,
                     "Error: one message could not be processed by "
                     "any parser, message is being discarded (start of raw "
                     "msg: '%.60s')",
                     pMsg->pszRawMsg);
        }
        DBGPRINTF("No parser could process the message (state %d), we need to "
                  "discard it.\n",
                  localRet);
        ABORT_FINALIZE(localRet);
    }
    pMsg->msgFlags &= ~NEEDS_PARSING; 
finalize_it:
    RETiRet;
}
static rsRetVal ParseMsg ( smsg_t * pMsg ) { rsRetVal localRet = RS_RET_ERR ; parserList_t * pParserList ; parser_t * pParser ; sbool bIsSanitized ; sbool bPRIisParsed ; static int iErrMsgRateLimiter = 0 ; DEFiRet ; if ( pMsg -> iLenRawMsg == 0 ) ABORT_FINALIZE ( RS_RET_EMPTY_MSG ) ; CHKiRet ( uncompressMessage ( pMsg ) ) ; DBGPRINTF ( " \n " , pMsg -> msgFlags , ( pMsg -> msgFlags & NEEDS_DNSRESOL ) ? UCHAR_CONSTANT ( " " ) : getRcvFrom ( pMsg ) , pMsg -> pszRawMsg ) ; pParserList = ruleset . GetParserList ( ourConf , pMsg ) ; if ( pParserList == NULL ) { pParserList = pDfltParsLst ; } DBGPRINTF ( " \n " , pParserList , ( pParserList == pDfltParsLst ) ? " " : " " ) ; bIsSanitized = RSFALSE ; bPRIisParsed = RSFALSE ; while ( pParserList != NULL ) { pParser = pParserList -> pParser ; if ( pParser -> bDoSanitazion && bIsSanitized == RSFALSE ) { CHKiRet ( SanitizeMsg ( pMsg ) ) ; if ( pParser -> bDoPRIParsing && bPRIisParsed == RSFALSE ) { CHKiRet ( ParsePRI ( pMsg ) ) ; bPRIisParsed = RSTRUE ; } bIsSanitized = RSTRUE ; } if ( pParser -> pModule -> mod . pm . parse2 == NULL ) localRet = pParser -> pModule -> mod . pm . parse ( pMsg ) ; else localRet = pParser -> pModule -> mod . pm . parse2 ( pParser -> pInst , pMsg ) ; DBGPRINTF ( " \n " , pParser -> pName , localRet ) ; if ( localRet != RS_RET_COULD_NOT_PARSE ) break ; pParserList = pParserList -> pNext ; } if ( localRet != RS_RET_OK ) { if ( ++ iErrMsgRateLimiter < 1000 ) { LogError ( 0 , localRet , " " " " " " , pMsg -> pszRawMsg ) ; } DBGPRINTF ( " " " \n " , localRet ) ; ABORT_FINALIZE ( localRet ) ; } pMsg -> msgFlags &= ~ NEEDS_PARSING ; finalize_it : RETiRet ; }
Parse a received message.
Parse a received message .
/* we take the risk to print a non-sanitized string, because this is the
     * best we can get (and that functionality is too important for debugging to
     * drop it...).
     */ /* we now need to go through our list of parsers and see which one is
     * capable of parsing the message. Note that the first parser that requires
     * message sanitization will cause it to happen. After that, access to the
     * unsanitized message is no loger possible.
     */ /* We need to log a warning message and drop the message if we did not find
     * a parser. Note that we log at most the first 1000 message, as this may
     * very well be a problem that causes a message generation loop. We do not
     * synchronize that counter, it doesn't matter if we log a handful messages
     * more than we should...
     */ /* "finalize" message object */ /* this message is now parsed */