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/template.c
struct template* tplAddLine(rsconf_t* conf, const char* pName,
                            uchar** ppRestOfConfLine)
{
    struct template* pTpl;
    unsigned char* p;
    int bDone;
    size_t i;
    rsRetVal localRet;

    assert(pName != NULL);
    assert(ppRestOfConfLine != NULL);
    if ((pTpl = tplConstruct(conf)) == NULL)
        return NULL;

    DBGPRINTF("tplAddLine processing template '%s'\n", pName);
    pTpl->iLenName = strlen(pName);
    pTpl->pszName = (char*)malloc(pTpl->iLenName + 1);
    if (pTpl->pszName == NULL)
    {
        dbgprintf("tplAddLine could not alloc memory for template name!");
        pTpl->iLenName = 0;
        return NULL;
        /* I know - we create a memory leak here - but I deem
         * it acceptable as it is a) a very small leak b) very
         * unlikely to happen. rgerhards 2004-11-17
         */
    }
    memcpy(pTpl->pszName, pName, pTpl->iLenName + 1);

    /* now actually parse the line */
    p = *ppRestOfConfLine;
    assert(p != NULL);

    while (isspace((int)*p)) /* skip whitespace */
        ++p;

    switch (*p)
    {
        case '"': /* just continue */
            break;
        case '=':
            *ppRestOfConfLine = p + 1;
            localRet = tplAddTplMod(pTpl, ppRestOfConfLine);
            if (localRet != RS_RET_OK)
            {
                LogError(0, localRet,
                         "Template '%s': error %d defining template via strgen "
                         "module",
                         pTpl->pszName, localRet);
                /* we simply make the template defunct in this case by setting
                 * its name to a zero-string. We do not free it, as this would
                 * require additional code and causes only a very small memory
                 * consumption. Memory is freed, however, in normal operation
                 * and most importantly by HUPing syslogd.
                 */
                *pTpl->pszName = '\0';
            }
            return NULL;
        default:
            dbgprintf("Template '%s' invalid, does not start with '\"'!\n",
                      pTpl->pszName);
            /* we simply make the template defunct in this case by setting
             * its name to a zero-string. We do not free it, as this would
             * require additional code and causes only a very small memory
             * consumption.
             */
            *pTpl->pszName = '\0';
            return NULL;
    }
    ++p;

    /* we finally go to the actual template string - so let's have some fun...
     */
    bDone = *p ? 0 : 1;
    while (!bDone)
    {
        switch (*p)
        {
            case '\0':
                bDone = 1;
                break;
            case '%': /* parameter */
                ++p;  /* eat '%' */
                if (do_Parameter(&p, pTpl) != RS_RET_OK)
                {
                    dbgprintf("tplAddLine error: parameter invalid");
                    return NULL;
                };
                break;
            default: /* constant */
                do_Constant(&p, pTpl, 1);
                break;
        }
        if (*p == '"')
        {        /* end of template string? */
            ++p; /* eat it! */
            bDone = 1;
        }
    }

    /* we now have the template - let's look at the options (if any)
     * we process options until we reach the end of the string or
     * an error occurs - whichever is first.
     */
    while (*p)
    {
        while (isspace((int)*p)) /* skip whitespace */
            ++p;

        if (*p != ',')
            break;
        ++p; /* eat ',' */

        while (isspace((int)*p)) /* skip whitespace */
            ++p;

        /* read option word */
        char optBuf[128] = {
            '\0'}; /* buffer for options - should be more than enough... */
        i = 0;
        while ((i < (sizeof(optBuf) - 1)) && *p && *p != '=' && *p != ',' &&
               *p != '\n')
        {
            optBuf[i++] = tolower((int)*p);
            ++p;
        }
        optBuf[i] = '\0';

        if (*p == '\n')
            ++p;

        /* as of now, the no form is nonsense... but I do include
         * it anyhow... ;) rgerhards 2004-11-22
         */
        if (!strcmp(optBuf, "stdsql"))
        {
            pTpl->optFormatEscape = STDSQL_ESCAPE;
        }
        else if (!strcmp(optBuf, "json"))
        {
            pTpl->optFormatEscape = JSON_ESCAPE;
        }
        else if (!strcmp(optBuf, "sql"))
        {
            pTpl->optFormatEscape = SQL_ESCAPE;
        }
        else if (!strcmp(optBuf, "nosql"))
        {
            pTpl->optFormatEscape = NO_ESCAPE;
        }
        else if (!strcmp(optBuf, "casesensitive"))
        {
            pTpl->optCaseSensitive = 1;
        }
        else
        {
            dbgprintf("Invalid option '%s' ignored.\n", optBuf);
        }
    }

    *ppRestOfConfLine = p;
    apply_case_sensitivity(pTpl);

    return (pTpl);
}
/* Add a new template line
 * returns pointer to new object if it succeeds, NULL otherwise.
 */
Add a new template line
returns pointer to new object if it succeeds, NULL otherwise.
Add a new template line returns pointer to new object if it succeeds NULL otherwise .
struct template* tplAddLine(rsconf_t* conf, const char* pName,
                            uchar** ppRestOfConfLine)
{
    struct template* pTpl;
    unsigned char* p;
    int bDone;
    size_t i;
    rsRetVal localRet;
    assert(pName != NULL);
    assert(ppRestOfConfLine != NULL);
    if ((pTpl = tplConstruct(conf)) == NULL)
        return NULL;
    DBGPRINTF("tplAddLine processing template '%s'\n", pName);
    pTpl->iLenName = strlen(pName);
    pTpl->pszName = (char*)malloc(pTpl->iLenName + 1);
    if (pTpl->pszName == NULL)
    {
        dbgprintf("tplAddLine could not alloc memory for template name!");
        pTpl->iLenName = 0;
        return NULL;
    }
    memcpy(pTpl->pszName, pName, pTpl->iLenName + 1);
    p = *ppRestOfConfLine;
    assert(p != NULL);
    while (isspace((int)*p)) 
        ++p;
    switch (*p)
    {
        case '"': 
            break;
        case '=':
            *ppRestOfConfLine = p + 1;
            localRet = tplAddTplMod(pTpl, ppRestOfConfLine);
            if (localRet != RS_RET_OK)
            {
                LogError(0, localRet,
                         "Template '%s': error %d defining template via strgen "
                         "module",
                         pTpl->pszName, localRet);
                *pTpl->pszName = '\0';
            }
            return NULL;
        default:
            dbgprintf("Template '%s' invalid, does not start with '\"'!\n",
                      pTpl->pszName);
            *pTpl->pszName = '\0';
            return NULL;
    }
    ++p;
    bDone = *p ? 0 : 1;
    while (!bDone)
    {
        switch (*p)
        {
            case '\0':
                bDone = 1;
                break;
            case '%': 
                ++p;  
                if (do_Parameter(&p, pTpl) != RS_RET_OK)
                {
                    dbgprintf("tplAddLine error: parameter invalid");
                    return NULL;
                };
                break;
            default: 
                do_Constant(&p, pTpl, 1);
                break;
        }
        if (*p == '"')
        {        
            ++p; 
            bDone = 1;
        }
    }
    while (*p)
    {
        while (isspace((int)*p)) 
            ++p;
        if (*p != ',')
            break;
        ++p; 
        while (isspace((int)*p)) 
            ++p;
        char optBuf[128] = {
            '\0'}; 
        i = 0;
        while ((i < (sizeof(optBuf) - 1)) && *p && *p != '=' && *p != ',' &&
               *p != '\n')
        {
            optBuf[i++] = tolower((int)*p);
            ++p;
        }
        optBuf[i] = '\0';
        if (*p == '\n')
            ++p;
        if (!strcmp(optBuf, "stdsql"))
        {
            pTpl->optFormatEscape = STDSQL_ESCAPE;
        }
        else if (!strcmp(optBuf, "json"))
        {
            pTpl->optFormatEscape = JSON_ESCAPE;
        }
        else if (!strcmp(optBuf, "sql"))
        {
            pTpl->optFormatEscape = SQL_ESCAPE;
        }
        else if (!strcmp(optBuf, "nosql"))
        {
            pTpl->optFormatEscape = NO_ESCAPE;
        }
        else if (!strcmp(optBuf, "casesensitive"))
        {
            pTpl->optCaseSensitive = 1;
        }
        else
        {
            dbgprintf("Invalid option '%s' ignored.\n", optBuf);
        }
    }
    *ppRestOfConfLine = p;
    apply_case_sensitivity(pTpl);
    return (pTpl);
}
struct template * tplAddLine ( rsconf_t * conf , const char * pName , uchar * * ppRestOfConfLine ) { struct template * pTpl ; unsigned char * p ; int bDone ; size_t i ; rsRetVal localRet ; assert ( pName != NULL ) ; assert ( ppRestOfConfLine != NULL ) ; if ( ( pTpl = tplConstruct ( conf ) ) == NULL ) return NULL ; DBGPRINTF ( " \n " , pName ) ; pTpl -> iLenName = strlen ( pName ) ; pTpl -> pszName = ( char * ) malloc ( pTpl -> iLenName + 1 ) ; if ( pTpl -> pszName == NULL ) { dbgprintf ( " " ) ; pTpl -> iLenName = 0 ; return NULL ; } memcpy ( pTpl -> pszName , pName , pTpl -> iLenName + 1 ) ; p = * ppRestOfConfLine ; assert ( p != NULL ) ; while ( isspace ( ( int ) * p ) ) ++ p ; switch ( * p ) { case ' ' : break ; case ' ' : * ppRestOfConfLine = p + 1 ; localRet = tplAddTplMod ( pTpl , ppRestOfConfLine ) ; if ( localRet != RS_RET_OK ) { LogError ( 0 , localRet , " " " " , pTpl -> pszName , localRet ) ; * pTpl -> pszName = ' \0 ' ; } return NULL ; default : dbgprintf ( " \" \n " , pTpl -> pszName ) ; * pTpl -> pszName = ' \0 ' ; return NULL ; } ++ p ; bDone = * p ? 0 : 1 ; while ( ! bDone ) { switch ( * p ) { case ' \0 ' : bDone = 1 ; break ; case ' ' : ++ p ; if ( do_Parameter ( & p , pTpl ) != RS_RET_OK ) { dbgprintf ( " " ) ; return NULL ; } ; break ; default : do_Constant ( & p , pTpl , 1 ) ; break ; } if ( * p == ' ' ) { ++ p ; bDone = 1 ; } } while ( * p ) { while ( isspace ( ( int ) * p ) ) ++ p ; if ( * p != ' ' ) break ; ++ p ; while ( isspace ( ( int ) * p ) ) ++ p ; char optBuf [ 128 ] = { ' \0 ' } ; i = 0 ; while ( ( i < ( sizeof ( optBuf ) - 1 ) ) && * p && * p != ' ' && * p != ' ' && * p != ' \n ' ) { optBuf [ i ++ ] = tolower ( ( int ) * p ) ; ++ p ; } optBuf [ i ] = ' \0 ' ; if ( * p == ' \n ' ) ++ p ; if ( ! strcmp ( optBuf , " " ) ) { pTpl -> optFormatEscape = STDSQL_ESCAPE ; } else if ( ! strcmp ( optBuf , " " ) ) { pTpl -> optFormatEscape = JSON_ESCAPE ; } else if ( ! strcmp ( optBuf , " " ) ) { pTpl -> optFormatEscape = SQL_ESCAPE ; } else if ( ! strcmp ( optBuf , " " ) ) { pTpl -> optFormatEscape = NO_ESCAPE ; } else if ( ! strcmp ( optBuf , " " ) ) { pTpl -> optCaseSensitive = 1 ; } else { dbgprintf ( " \n " , optBuf ) ; } } * ppRestOfConfLine = p ; apply_case_sensitivity ( pTpl ) ; return ( pTpl ) ; }
Add a new template line
 returns pointer to new object if it succeeds, NULL otherwise.
Add a new template line returns pointer to new object if it succeeds NULL otherwise .
/* I know - we create a memory leak here - but I deem
         * it acceptable as it is a) a very small leak b) very
         * unlikely to happen. rgerhards 2004-11-17
         */ /* now actually parse the line */ /* skip whitespace */ /* just continue */ /* we simply make the template defunct in this case by setting
                 * its name to a zero-string. We do not free it, as this would
                 * require additional code and causes only a very small memory
                 * consumption. Memory is freed, however, in normal operation
                 * and most importantly by HUPing syslogd.
                 */ /* we simply make the template defunct in this case by setting
             * its name to a zero-string. We do not free it, as this would
             * require additional code and causes only a very small memory
             * consumption.
             */ /* we finally go to the actual template string - so let's have some fun...
     */ /* parameter */ /* eat '%' */ /* constant */ /* end of template string? */ /* eat it! */ /* we now have the template - let's look at the options (if any)
     * we process options until we reach the end of the string or
     * an error occurs - whichever is first.
     */ /* skip whitespace */ /* eat ',' */ /* skip whitespace */ /* read option word */ /* buffer for options - should be more than enough... */ /* as of now, the no form is nonsense... but I do include
         * it anyhow... ;) rgerhards 2004-11-22
         */