diff --git a/src/cas/generic/casClient.cc b/src/cas/generic/casClient.cc index 883f62fe9..d3efc8b6d 100644 --- a/src/cas/generic/casClient.cc +++ b/src/cas/generic/casClient.cc @@ -575,11 +575,7 @@ caStatus casClient::logBadIdWithFileAndLineno ( const caHdrLargeArray * mp, void casClient::dumpMsg ( const caHdrLargeArray *mp, const void *dp, const char *pFormat, ... ) { - casChannelI *pciu; - char pName[64u]; - char pPVName[64u]; - va_list theArgs; - + va_list theArgs; if ( pFormat ) { va_start ( theArgs, pFormat ); errlogPrintf ( "CAS: " ); @@ -587,10 +583,12 @@ void casClient::dumpMsg ( const caHdrLargeArray *mp, va_end ( theArgs ); } + char pName[64u]; this->hostName (pName, sizeof (pName)); - pciu = this->resIdToChannel(mp->m_cid); + casChannelI * pciu = this->resIdToChannel(mp->m_cid); + char pPVName[64u]; if (pciu) { strncpy(pPVName, pciu->getPVI().getName(), sizeof(pPVName)); if (&pciu->getClient()!=this) { @@ -601,10 +599,16 @@ void casClient::dumpMsg ( const caHdrLargeArray *mp, else { sprintf(pPVName,"%u", mp->m_cid); } - errlogPrintf( + + char pUserName[32]; + this->userName ( pUserName, sizeof ( pUserName) ); + char pHostName[32]; + this->hostName ( pHostName, sizeof ( pHostName) ); + + errlogPrintf ( "CAS: %s on %s at %s: cmd=%d cid=%s typ=%d cnt=%d psz=%d avail=%x\n", - this->userName(), - this->hostName(), + pUserName, + pHostName, pName, mp->m_cmmd, pPVName, @@ -617,15 +621,3 @@ void casClient::dumpMsg ( const caHdrLargeArray *mp, errlogPrintf("CAS: The string written: %s \n", (char *)dp); } } - -// -// -// -const char *casClient::hostName() const -{ - return "?"; -} -const char *casClient::userName() const -{ - return "?"; -} diff --git a/src/cas/generic/casDGClient.cc b/src/cas/generic/casDGClient.cc index 5dcef7741..1432712b6 100644 --- a/src/cas/generic/casDGClient.cc +++ b/src/cas/generic/casDGClient.cc @@ -602,7 +602,16 @@ caNetAddr casDGClient::fetchLastRecvAddr () const // // casDGClient::hostName() // -void casDGClient::hostName (char *pBufIn, unsigned bufSizeIn) const +void casDGClient::hostName ( char *pBufIn, unsigned bufSizeIn ) const { - this->lastRecvAddr.stringConvert (pBufIn, bufSizeIn); + this->lastRecvAddr.stringConvert ( pBufIn, bufSizeIn ); } + +void casDGClient::userName ( char * pBuf, unsigned bufSizeIn ) const +{ + if ( bufSizeIn ) { + strncpy ( pBuf, "?", bufSizeIn ); + pBuf[bufSizeIn - 1] = '\0'; + } +} + diff --git a/src/cas/generic/casStrmClient.cc b/src/cas/generic/casStrmClient.cc index 4954990df..955599576 100644 --- a/src/cas/generic/casStrmClient.cc +++ b/src/cas/generic/casStrmClient.cc @@ -1852,17 +1852,13 @@ caStatus casStrmClient::read (smartGDDPointer &pDescRet) // // casStrmClient::userName() // -const char *casStrmClient::userName() const +void casStrmClient::userName ( char * pBuf, unsigned bufSize ) const { - return this->pUserName?this->pUserName:"?"; -} - -// -// casStrmClient::hostName() -// -const char *casStrmClient::hostName() const -{ - return this->pHostName?this->pHostName:"?"; + if ( bufSize ) { + const char *pName = this->pUserName ? this->pUserName : "?"; + strncpy ( pBuf, pName, bufSize ); + pBuf [bufSize-1] = '\0'; + } } // diff --git a/src/cas/generic/server.h b/src/cas/generic/server.h index 489c7f8c6..2d989a8d8 100644 --- a/src/cas/generic/server.h +++ b/src/cas/generic/server.h @@ -570,11 +570,7 @@ private: virtual caStatus hostNameAction (); virtual caStatus echoAction (); - // - // obtain the user name and host from the derived class - // - virtual const char *hostName() const; - virtual const char *userName() const; + virtual void userName ( char * pBuf, unsigned bufSize ) const = 0; // // static members @@ -624,19 +620,15 @@ public: caStatus monitorResponse ( casChannelI & chan, const caHdrLargeArray & msg, const smartConstGDDPointer & pDesc, const caStatus status ); - caStatus noReadAccessEvent(casClientMon *); + caStatus noReadAccessEvent( casClientMon * ); - // - // obtain the user name and host - // - const char *hostName () const; - const char *userName () const; - caStatus disconnectChan (caResId id); + caStatus disconnectChan ( caResId id ); - unsigned getDebugLevel() const; + unsigned getDebugLevel () const; - virtual void hostName (char *pBuf, unsigned bufSize) const = 0; + virtual void hostName ( char * pBuf, unsigned bufSize ) const = 0; + void userName ( char * pBuf, unsigned bufSize ) const; protected: @@ -739,20 +731,20 @@ public: // void sendBeacon ( ca_uint32_t beaconNumber ); - virtual void sendBeaconIO (char &msg, bufSizeT length, - aitUint16 &portField, aitUint32 &addrField) = 0; + virtual void sendBeaconIO ( char &msg, bufSizeT length, + aitUint16 &portField, aitUint32 &addrField ) = 0; - void destroy(); + void destroy (); - unsigned getDebugLevel() const; + unsigned getDebugLevel () const; - void hostName (char *pBuf, unsigned bufSize) const; + void hostName ( char * pBuf, unsigned bufSize ) const; + void userName ( char * pBuf, unsigned bufSize ) const; caNetAddr fetchLastRecvAddr () const; virtual caNetAddr serverAddress () const = 0; - protected: casProcCond eventSysProcess()