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/msg.c
static rsRetVal jsonAddVal(uchar * pSrc, unsigned buflen, es_str_t** dst,
                               int escapeAll)
    {
        unsigned char c;
        es_size_t i;
        char numbuf[4];
        unsigned ni;
        unsigned char nc;
        int j;
        DEFiRet;

        for (i = 0; i < buflen; ++i)
        {
            c = pSrc[i];
            if ((c >= 0x23 && c <= 0x2e) || (c >= 0x30 && c <= 0x5b) ||
                (c >= 0x5d /* && c <= 0x10FFFF*/) || c == 0x20 || c == 0x21)
            {
                /* no need to escape */
                if (*dst != NULL)
                    es_addChar(dst, c);
            }
            else
            {
                if (*dst == NULL)
                {
                    if (i == 0)
                    {
                        /* we hope we have only few escapes... */
                        *dst = es_newStr(buflen + 10);
                    }
                    else
                    {
                        *dst = es_newStrFromBuf((char*)pSrc, i);
                    }
                    if (*dst == NULL)
                    {
                        ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
                    }
                }
                /* we must escape, try RFC4627-defined special sequences first
                 */
                switch (c)
                {
                    case '\0':
                        es_addBuf(dst, "\\u0000", 6);
                        break;
                    case '\"':
                        es_addBuf(dst, "\\\"", 2);
                        break;
                    case '/':
                        es_addBuf(dst, "\\/", 2);
                        break;
                    case '\\':
                        if (escapeAll == RSFALSE)
                        {
                            ni = i + 1;
                            if (ni <= buflen)
                            {
                                nc = pSrc[ni];

                                /* Attempt to not double encode */
                                if (nc == '"' || nc == '/' || nc == '\\' ||
                                    nc == 'b' || nc == 'f' || nc == 'n' ||
                                    nc == 'r' || nc == 't' || nc == 'u')
                                {

                                    es_addChar(dst, c);
                                    es_addChar(dst, nc);
                                    i = ni;
                                    break;
                                }
                            }
                        }

                        es_addBuf(dst, "\\\\", 2);
                        break;
                    case '\010':
                        es_addBuf(dst, "\\b", 2);
                        break;
                    case '\014':
                        es_addBuf(dst, "\\f", 2);
                        break;
                    case '\n':
                        es_addBuf(dst, "\\n", 2);
                        break;
                    case '\r':
                        es_addBuf(dst, "\\r", 2);
                        break;
                    case '\t':
                        es_addBuf(dst, "\\t", 2);
                        break;
                    default:
                        /* TODO : proper Unicode encoding (see header comment)
                         */
                        for (j = 0; j < 4; ++j)
                        {
                            numbuf[3 - j] = hexdigit[c % 16];
                            c = c / 16;
                        }
                        es_addBuf(dst, "\\u", 2);
                        es_addBuf(dst, numbuf, 4);
                        break;
                }
            }
        }
    finalize_it:
        RETiRet;
    }
/* Encode a JSON value and add it to provided string. Note that
     * the string object may be NULL. In this case, it is created
     * if and only if escaping is needed. if escapeAll is false, previously
     * escaped strings are left as is
     */
Encode a JSON value and add it to provided string. Note that
the string object may be NULL. In this case, it is created
if and only if escaping is needed. if escapeAll is false, previously
escaped strings are left as is
Encode a JSON value and add it to provided string . Note that the string object may be NULL . In this case it is created if and only if escaping is needed . if escapeAll is false previously escaped strings are left as is
static rsRetVal jsonAddVal(uchar * pSrc, unsigned buflen, es_str_t** dst,
                               int escapeAll)
    {
        unsigned char c;
        es_size_t i;
        char numbuf[4];
        unsigned ni;
        unsigned char nc;
        int j;
        DEFiRet;
        for (i = 0; i < buflen; ++i)
        {
            c = pSrc[i];
            if ((c >= 0x23 && c <= 0x2e) || (c >= 0x30 && c <= 0x5b) ||
                (c >= 0x5d ) || c == 0x20 || c == 0x21)
            {
                if (*dst != NULL)
                    es_addChar(dst, c);
            }
            else
            {
                if (*dst == NULL)
                {
                    if (i == 0)
                    {
                        *dst = es_newStr(buflen + 10);
                    }
                    else
                    {
                        *dst = es_newStrFromBuf((char*)pSrc, i);
                    }
                    if (*dst == NULL)
                    {
                        ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
                    }
                }
                switch (c)
                {
                    case '\0':
                        es_addBuf(dst, "\\u0000", 6);
                        break;
                    case '\"':
                        es_addBuf(dst, "\\\"", 2);
                        break;
                    case '/':
                        es_addBuf(dst, "\\/", 2);
                        break;
                    case '\\':
                        if (escapeAll == RSFALSE)
                        {
                            ni = i + 1;
                            if (ni <= buflen)
                            {
                                nc = pSrc[ni];
                                if (nc == '"' || nc == '/' || nc == '\\' ||
                                    nc == 'b' || nc == 'f' || nc == 'n' ||
                                    nc == 'r' || nc == 't' || nc == 'u')
                                {
                                    es_addChar(dst, c);
                                    es_addChar(dst, nc);
                                    i = ni;
                                    break;
                                }
                            }
                        }
                        es_addBuf(dst, "\\\\", 2);
                        break;
                    case '\010':
                        es_addBuf(dst, "\\b", 2);
                        break;
                    case '\014':
                        es_addBuf(dst, "\\f", 2);
                        break;
                    case '\n':
                        es_addBuf(dst, "\\n", 2);
                        break;
                    case '\r':
                        es_addBuf(dst, "\\r", 2);
                        break;
                    case '\t':
                        es_addBuf(dst, "\\t", 2);
                        break;
                    default:
                        for (j = 0; j < 4; ++j)
                        {
                            numbuf[3 - j] = hexdigit[c % 16];
                            c = c / 16;
                        }
                        es_addBuf(dst, "\\u", 2);
                        es_addBuf(dst, numbuf, 4);
                        break;
                }
            }
        }
    finalize_it:
        RETiRet;
    }
static rsRetVal jsonAddVal ( uchar * pSrc , unsigned buflen , es_str_t * * dst , int escapeAll ) { unsigned char c ; es_size_t i ; char numbuf [ 4 ] ; unsigned ni ; unsigned char nc ; int j ; DEFiRet ; for ( i = 0 ; i < buflen ; ++ i ) { c = pSrc [ i ] ; if ( ( c >= 0x23 && c <= 0x2e ) || ( c >= 0x30 && c <= 0x5b ) || ( c >= 0x5d ) || c == 0x20 || c == 0x21 ) { if ( * dst != NULL ) es_addChar ( dst , c ) ; } else { if ( * dst == NULL ) { if ( i == 0 ) { * dst = es_newStr ( buflen + 10 ) ; } else { * dst = es_newStrFromBuf ( ( char * ) pSrc , i ) ; } if ( * dst == NULL ) { ABORT_FINALIZE ( RS_RET_OUT_OF_MEMORY ) ; } } switch ( c ) { case ' \0 ' : es_addBuf ( dst , " \\ " , 6 ) ; break ; case ' \" ' : es_addBuf ( dst , " \\ \" " , 2 ) ; break ; case ' ' : es_addBuf ( dst , " \\ " , 2 ) ; break ; case ' \\ ' : if ( escapeAll == RSFALSE ) { ni = i + 1 ; if ( ni <= buflen ) { nc = pSrc [ ni ] ; if ( nc == ' ' || nc == ' ' || nc == ' \\ ' || nc == ' ' || nc == ' ' || nc == ' ' || nc == ' ' || nc == ' ' || nc == ' ' ) { es_addChar ( dst , c ) ; es_addChar ( dst , nc ) ; i = ni ; break ; } } } es_addBuf ( dst , " \\ \\ " , 2 ) ; break ; case ' \010 ' : es_addBuf ( dst , " \\ " , 2 ) ; break ; case ' \014 ' : es_addBuf ( dst , " \\ " , 2 ) ; break ; case ' \n ' : es_addBuf ( dst , " \\ " , 2 ) ; break ; case ' \r ' : es_addBuf ( dst , " \\ " , 2 ) ; break ; case ' \t ' : es_addBuf ( dst , " \\ " , 2 ) ; break ; default : for ( j = 0 ; j < 4 ; ++ j ) { numbuf [ 3 - j ] = hexdigit [ c % 16 ] ; c = c / 16 ; } es_addBuf ( dst , " \\ " , 2 ) ; es_addBuf ( dst , numbuf , 4 ) ; break ; } } } finalize_it : RETiRet ; }
Encode a JSON value and add it to provided string.
Encode a JSON value and add it to provided string .
/* && c <= 0x10FFFF*/ /* no need to escape */ /* we hope we have only few escapes... */ /* we must escape, try RFC4627-defined special sequences first
                 */ /* Attempt to not double encode */ /* TODO : proper Unicode encoding (see header comment)
                         */