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
smsg_t* MsgDup(smsg_t * pOld)
    {
        smsg_t* pNew;
        rsRetVal localRet;

        assert(pOld != NULL);

        if (msgConstructWithTime(&pNew, &pOld->tTIMESTAMP, pOld->ttGenTime) !=
            RS_RET_OK)
        {
            return NULL;
        }

        /* now copy the message properties */
        pNew->iRefCount = 1;
        pNew->iSeverity = pOld->iSeverity;
        pNew->iFacility = pOld->iFacility;
        pNew->msgFlags = pOld->msgFlags;
        pNew->iProtocolVersion = pOld->iProtocolVersion;
        pNew->ttGenTime = pOld->ttGenTime;
        pNew->offMSG = pOld->offMSG;
        pNew->iLenRawMsg = pOld->iLenRawMsg;
        pNew->iLenMSG = pOld->iLenMSG;
        pNew->iLenTAG = pOld->iLenTAG;
        pNew->iLenHOSTNAME = pOld->iLenHOSTNAME;
        if ((pOld->msgFlags & NEEDS_DNSRESOL))
        {
            localRet = msgSetFromSockinfo(pNew, pOld->rcvFrom.pfrominet);
            if (localRet != RS_RET_OK)
            {
                /* if something fails, we accept loss of this property, it is
                 * better than losing the whole message.
                 */
                pNew->msgFlags &= ~NEEDS_DNSRESOL;
                pNew->rcvFrom.pRcvFrom =
                    NULL; /* make sure no dangling values */
            }
        }
        else
        {
            if (pOld->rcvFrom.pRcvFrom != NULL)
            {
                pNew->rcvFrom.pRcvFrom = pOld->rcvFrom.pRcvFrom;
                prop.AddRef(pNew->rcvFrom.pRcvFrom);
            }
        }
        if (pOld->pRcvFromIP != NULL)
        {
            pNew->pRcvFromIP = pOld->pRcvFromIP;
            prop.AddRef(pNew->pRcvFromIP);
        }
        if (pOld->pInputName != NULL)
        {
            pNew->pInputName = pOld->pInputName;
            prop.AddRef(pNew->pInputName);
        }
        if (pOld->iLenTAG > 0)
        {
            if (pOld->iLenTAG < CONF_TAG_BUFSIZE)
            {
                memcpy(pNew->TAG.szBuf, pOld->TAG.szBuf, pOld->iLenTAG + 1);
            }
            else
            {
                if ((pNew->TAG.pszTAG =
                         srUtilStrDup(pOld->TAG.pszTAG, pOld->iLenTAG)) == NULL)
                {
                    msgDestruct(&pNew);
                    return NULL;
                }
                pNew->iLenTAG = pOld->iLenTAG;
            }
        }
        if (pOld->pszRawMsg == pOld->szRawMsg)
        {
            memcpy(pNew->szRawMsg, pOld->szRawMsg, pOld->iLenRawMsg + 1);
            pNew->pszRawMsg = pNew->szRawMsg;
        }
        else
        {
            tmpCOPYSZ(RawMsg);
        }
        if (pOld->pszHOSTNAME == NULL)
        {
            pNew->pszHOSTNAME = NULL;
        }
        else
        {
            if (pOld->iLenHOSTNAME < CONF_HOSTNAME_BUFSIZE)
            {
                memcpy(pNew->szHOSTNAME, pOld->szHOSTNAME,
                       pOld->iLenHOSTNAME + 1);
                pNew->pszHOSTNAME = pNew->szHOSTNAME;
            }
            else
            {
                tmpCOPYSZ(HOSTNAME);
            }
        }
        if (pOld->pszStrucData == NULL)
        {
            pNew->pszStrucData = NULL;
        }
        else
        {
            pNew->pszStrucData = (uchar*)strdup((char*)pOld->pszStrucData);
            pNew->lenStrucData = pOld->lenStrucData;
        }

        tmpCOPYCSTR(APPNAME);
        tmpCOPYCSTR(PROCID);
        tmpCOPYCSTR(MSGID);

        if (pOld->json != NULL)
            pNew->json = jsonDeepCopy(pOld->json);
        if (pOld->localvars != NULL)
            pNew->localvars = jsonDeepCopy(pOld->localvars);

        /* we do not copy all other cache properties, as we do not even know
         * if they are needed once again. So we let them re-create if needed.
         */

        return pNew;
    }
/* Constructs a message object by duplicating another one.
         * Returns NULL if duplication failed. We do not need to lock the
         * message object here, because a fully-created msg object is never
         * allowed to be manipulated. For this, MsgDup() must be used, so
         * MsgDup() can never run into a situation where the message object is
         * being modified while its content is copied - it's forbidden by
         * definition. rgerhards, 2007-07-10
         */
Constructs a message object by duplicating another one.
Returns NULL if duplication failed. We do not need to lock the
message object here, because a fully-created msg object is never
allowed to be manipulated. For this, MsgDup() must be used, so
MsgDup() can never run into a situation where the message object is
being modified while its content is copied - it's forbidden by
definition.
Constructs a message object by duplicating another one . Returns NULL if duplication failed . We do not need to lock the message object here because a fully - created msg object is never allowed to be manipulated . For this MsgDup () must be used so MsgDup () can never run into a situation where the message object is being modified while its content is copied - it ' s forbidden by definition .
smsg_t* MsgDup(smsg_t * pOld)
    {
        smsg_t* pNew;
        rsRetVal localRet;
        assert(pOld != NULL);
        if (msgConstructWithTime(&pNew, &pOld->tTIMESTAMP, pOld->ttGenTime) !=
            RS_RET_OK)
        {
            return NULL;
        }
        pNew->iRefCount = 1;
        pNew->iSeverity = pOld->iSeverity;
        pNew->iFacility = pOld->iFacility;
        pNew->msgFlags = pOld->msgFlags;
        pNew->iProtocolVersion = pOld->iProtocolVersion;
        pNew->ttGenTime = pOld->ttGenTime;
        pNew->offMSG = pOld->offMSG;
        pNew->iLenRawMsg = pOld->iLenRawMsg;
        pNew->iLenMSG = pOld->iLenMSG;
        pNew->iLenTAG = pOld->iLenTAG;
        pNew->iLenHOSTNAME = pOld->iLenHOSTNAME;
        if ((pOld->msgFlags & NEEDS_DNSRESOL))
        {
            localRet = msgSetFromSockinfo(pNew, pOld->rcvFrom.pfrominet);
            if (localRet != RS_RET_OK)
            {
                pNew->msgFlags &= ~NEEDS_DNSRESOL;
                pNew->rcvFrom.pRcvFrom =
                    NULL; 
            }
        }
        else
        {
            if (pOld->rcvFrom.pRcvFrom != NULL)
            {
                pNew->rcvFrom.pRcvFrom = pOld->rcvFrom.pRcvFrom;
                prop.AddRef(pNew->rcvFrom.pRcvFrom);
            }
        }
        if (pOld->pRcvFromIP != NULL)
        {
            pNew->pRcvFromIP = pOld->pRcvFromIP;
            prop.AddRef(pNew->pRcvFromIP);
        }
        if (pOld->pInputName != NULL)
        {
            pNew->pInputName = pOld->pInputName;
            prop.AddRef(pNew->pInputName);
        }
        if (pOld->iLenTAG > 0)
        {
            if (pOld->iLenTAG < CONF_TAG_BUFSIZE)
            {
                memcpy(pNew->TAG.szBuf, pOld->TAG.szBuf, pOld->iLenTAG + 1);
            }
            else
            {
                if ((pNew->TAG.pszTAG =
                         srUtilStrDup(pOld->TAG.pszTAG, pOld->iLenTAG)) == NULL)
                {
                    msgDestruct(&pNew);
                    return NULL;
                }
                pNew->iLenTAG = pOld->iLenTAG;
            }
        }
        if (pOld->pszRawMsg == pOld->szRawMsg)
        {
            memcpy(pNew->szRawMsg, pOld->szRawMsg, pOld->iLenRawMsg + 1);
            pNew->pszRawMsg = pNew->szRawMsg;
        }
        else
        {
            tmpCOPYSZ(RawMsg);
        }
        if (pOld->pszHOSTNAME == NULL)
        {
            pNew->pszHOSTNAME = NULL;
        }
        else
        {
            if (pOld->iLenHOSTNAME < CONF_HOSTNAME_BUFSIZE)
            {
                memcpy(pNew->szHOSTNAME, pOld->szHOSTNAME,
                       pOld->iLenHOSTNAME + 1);
                pNew->pszHOSTNAME = pNew->szHOSTNAME;
            }
            else
            {
                tmpCOPYSZ(HOSTNAME);
            }
        }
        if (pOld->pszStrucData == NULL)
        {
            pNew->pszStrucData = NULL;
        }
        else
        {
            pNew->pszStrucData = (uchar*)strdup((char*)pOld->pszStrucData);
            pNew->lenStrucData = pOld->lenStrucData;
        }
        tmpCOPYCSTR(APPNAME);
        tmpCOPYCSTR(PROCID);
        tmpCOPYCSTR(MSGID);
        if (pOld->json != NULL)
            pNew->json = jsonDeepCopy(pOld->json);
        if (pOld->localvars != NULL)
            pNew->localvars = jsonDeepCopy(pOld->localvars);
        return pNew;
    }
smsg_t * MsgDup ( smsg_t * pOld ) { smsg_t * pNew ; rsRetVal localRet ; assert ( pOld != NULL ) ; if ( msgConstructWithTime ( & pNew , & pOld -> tTIMESTAMP , pOld -> ttGenTime ) != RS_RET_OK ) { return NULL ; } pNew -> iRefCount = 1 ; pNew -> iSeverity = pOld -> iSeverity ; pNew -> iFacility = pOld -> iFacility ; pNew -> msgFlags = pOld -> msgFlags ; pNew -> iProtocolVersion = pOld -> iProtocolVersion ; pNew -> ttGenTime = pOld -> ttGenTime ; pNew -> offMSG = pOld -> offMSG ; pNew -> iLenRawMsg = pOld -> iLenRawMsg ; pNew -> iLenMSG = pOld -> iLenMSG ; pNew -> iLenTAG = pOld -> iLenTAG ; pNew -> iLenHOSTNAME = pOld -> iLenHOSTNAME ; if ( ( pOld -> msgFlags & NEEDS_DNSRESOL ) ) { localRet = msgSetFromSockinfo ( pNew , pOld -> rcvFrom . pfrominet ) ; if ( localRet != RS_RET_OK ) { pNew -> msgFlags &= ~ NEEDS_DNSRESOL ; pNew -> rcvFrom . pRcvFrom = NULL ; } } else { if ( pOld -> rcvFrom . pRcvFrom != NULL ) { pNew -> rcvFrom . pRcvFrom = pOld -> rcvFrom . pRcvFrom ; prop . AddRef ( pNew -> rcvFrom . pRcvFrom ) ; } } if ( pOld -> pRcvFromIP != NULL ) { pNew -> pRcvFromIP = pOld -> pRcvFromIP ; prop . AddRef ( pNew -> pRcvFromIP ) ; } if ( pOld -> pInputName != NULL ) { pNew -> pInputName = pOld -> pInputName ; prop . AddRef ( pNew -> pInputName ) ; } if ( pOld -> iLenTAG > 0 ) { if ( pOld -> iLenTAG < CONF_TAG_BUFSIZE ) { memcpy ( pNew -> TAG . szBuf , pOld -> TAG . szBuf , pOld -> iLenTAG + 1 ) ; } else { if ( ( pNew -> TAG . pszTAG = srUtilStrDup ( pOld -> TAG . pszTAG , pOld -> iLenTAG ) ) == NULL ) { msgDestruct ( & pNew ) ; return NULL ; } pNew -> iLenTAG = pOld -> iLenTAG ; } } if ( pOld -> pszRawMsg == pOld -> szRawMsg ) { memcpy ( pNew -> szRawMsg , pOld -> szRawMsg , pOld -> iLenRawMsg + 1 ) ; pNew -> pszRawMsg = pNew -> szRawMsg ; } else { tmpCOPYSZ ( RawMsg ) ; } if ( pOld -> pszHOSTNAME == NULL ) { pNew -> pszHOSTNAME = NULL ; } else { if ( pOld -> iLenHOSTNAME < CONF_HOSTNAME_BUFSIZE ) { memcpy ( pNew -> szHOSTNAME , pOld -> szHOSTNAME , pOld -> iLenHOSTNAME + 1 ) ; pNew -> pszHOSTNAME = pNew -> szHOSTNAME ; } else { tmpCOPYSZ ( HOSTNAME ) ; } } if ( pOld -> pszStrucData == NULL ) { pNew -> pszStrucData = NULL ; } else { pNew -> pszStrucData = ( uchar * ) strdup ( ( char * ) pOld -> pszStrucData ) ; pNew -> lenStrucData = pOld -> lenStrucData ; } tmpCOPYCSTR ( APPNAME ) ; tmpCOPYCSTR ( PROCID ) ; tmpCOPYCSTR ( MSGID ) ; if ( pOld -> json != NULL ) pNew -> json = jsonDeepCopy ( pOld -> json ) ; if ( pOld -> localvars != NULL ) pNew -> localvars = jsonDeepCopy ( pOld -> localvars ) ; return pNew ; }
Constructs a message object by duplicating another one.
Constructs a message object by duplicating another one .
/* now copy the message properties */ /* if something fails, we accept loss of this property, it is
                 * better than losing the whole message.
                 */ /* make sure no dangling values */ /* we do not copy all other cache properties, as we do not even know
         * if they are needed once again. So we let them re-create if needed.
         */