Mixe for Privacy and Anonymity in the Internet
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
CAMsg Class Reference

#include <CAMsg.hpp>

Collaboration diagram for CAMsg:
[legend]

List of all members.

Public Member Functions

 ~CAMsg ()

Static Public Member Functions

static SINT32 init ()
static SINT32 cleanup ()
static SINT32 setLogOptions (UINT32 options)
static SINT32 setLogLevel (UINT32 a_logLevel)
static SINT32 setMaxLogFileSize (UINT64 size)
static SINT32 printMsg (UINT32 typ, const char *format,...)
static SINT32 openEncryptedLog ()
 Open a log, where the logged messages are store encrypted.
static SINT32 closeEncryptedLog ()

Private Member Functions

 CAMsg ()
SINT32 openLog (UINT32 type)
SINT32 closeLog ()
SINT32 rotateLog ()
char * createLogFileMessage (UINT32 opt)
char * createLogDirMessage (UINT32 opt)

Private Attributes

SINT64 m_maxLogFileSize
UINT32 m_NrOfWrites
UINT32 m_uLogType
UINT32 m_logLevel
UINT32 m_lastLogFileNumber
bool m_alreadyOpened
int m_hFileEncrypted
int m_hFileInfo
char * m_strMsgBuff
char * m_strLogFile
char * m_strLogDir
CAMutexm_pcsPrint
t_LogEncCipherm_pCipher

Static Private Attributes

static CAMsgpMsg = NULL
static const char *const m_strMsgTypes [6] = {", error ] ",", critical] ",", info ] ",", debug ] ",", special ] ",", warning ] "}

Detailed Description

Definition at line 59 of file CAMsg.hpp.


Constructor & Destructor Documentation

CAMsg::CAMsg ( ) [private]

Definition at line 49 of file CAMsg.cpp.

References m_alreadyOpened, m_hFileEncrypted, m_hFileInfo, m_lastLogFileNumber, m_logLevel, m_maxLogFileSize, m_pCipher, m_pcsPrint, m_strLogFile, m_strMsgBuff, m_uLogType, MAX_MSG_SIZE, MSG_STDOUT, setZero64(), and STRMSGTYPES_SIZE.

Referenced by init().

    {
      m_pcsPrint=new CAMutex();
      m_logLevel = LOG_DEBUG;
      setZero64(m_maxLogFileSize);
      m_strMsgBuff=new char[MAX_MSG_SIZE+1+20+STRMSGTYPES_SIZE];
      m_uLogType=MSG_STDOUT;
      m_hFileInfo=-1;
      m_hFileEncrypted=-1;
      m_strLogFile=new char[1024];
      m_strMsgBuff[0]='[';
#ifdef COMPRESSED_LOGS
      m_gzFileInfo=NULL;
#endif
      m_pCipher=NULL;
      m_lastLogFileNumber = 0;
      m_alreadyOpened = false;
    }

Here is the call graph for this function:

Definition at line 68 of file CAMsg.cpp.

References closeEncryptedLog(), closeLog(), m_pcsPrint, m_strLogFile, and m_strMsgBuff.

    {
      closeLog();
#ifndef ONLY_LOCAL_PROXY
      closeEncryptedLog();
#endif
      delete[] m_strMsgBuff;
      m_strMsgBuff = NULL;
      delete[] m_strLogFile;
      m_strLogFile = NULL;
      delete m_pcsPrint;
      m_pcsPrint = NULL;
    }

Here is the call graph for this function:


Member Function Documentation

static SINT32 CAMsg::cleanup ( ) [inline, static]

Definition at line 74 of file CAMsg.hpp.

References closeLog(), E_SUCCESS, and pMsg.

Referenced by main().

      {
        if (pMsg != NULL)
        {
          pMsg->closeLog();
        }
        delete pMsg;
        pMsg = NULL;
        return E_SUCCESS;
      }

Here is the call graph for this function:

Definition at line 529 of file CAMsg.cpp.

References E_SUCCESS, m_hFileEncrypted, m_pCipher, and pMsg.

Referenced by ~CAMsg().

  {
    if(pMsg->m_hFileEncrypted>=0)
      {
        close(pMsg->m_hFileEncrypted);
      }
    delete pMsg->m_pCipher;
    pMsg->m_pCipher=NULL;
    pMsg->m_hFileEncrypted=-1;
    return E_SUCCESS;
  }
SINT32 CAMsg::closeLog ( ) [private]

Definition at line 366 of file CAMsg.cpp.

References E_SUCCESS, m_hFileInfo, m_uLogType, MSG_COMPRESSED_FILE, MSG_FILE, MSG_LOG, and pMsg.

Referenced by cleanup(), printMsg(), setLogOptions(), and ~CAMsg().

  {
        if ((pMsg->m_uLogType & MSG_LOG) == MSG_LOG)
        {
#ifndef _WIN32
          ::closelog();
#endif
        }
#ifdef COMPRESSED_LOGS
        if ((pMsg->m_uLogType & MSG_COMPRESSED_FILE) == MSG_COMPRESSED_FILE)
        {
          if(m_gzFileInfo!=NULL)
            gzclose(m_gzFileInfo);
          m_gzFileInfo=NULL;
        }
#endif
        else if ((pMsg->m_uLogType & MSG_FILE) == MSG_FILE)
        {
          if(m_hFileInfo!=-1)
            close(m_hFileInfo);
          m_hFileInfo=-1;
        }
    return E_SUCCESS;
  }
char * CAMsg::createLogDirMessage ( UINT32  opt) [private]

Definition at line 104 of file CAMsg.cpp.

References m_strLogDir, MSG_COMPRESSED_FILE, MSG_FILE, and pMsg.

Referenced by setLogOptions().

{
  const char* strLogAtPath = " Please also check if the directory '%s' exists and create or change it if it does not.";
  char* strLogFile = NULL;


  if ((opt & MSG_FILE) == MSG_FILE || (opt & MSG_COMPRESSED_FILE) == MSG_COMPRESSED_FILE)
  {
    if (pMsg->m_strLogDir != NULL)
    {
      strLogFile = new char[strlen(strLogAtPath) + strlen(pMsg->m_strLogDir) + 1];
      sprintf(strLogFile, strLogAtPath, pMsg->m_strLogDir);
    }
  }
  if (strLogFile == NULL)
  {
    strLogFile = new char[1];
    strLogFile[0] = '\0';
  }
  return strLogFile;
}
char * CAMsg::createLogFileMessage ( UINT32  opt) [private]

Definition at line 82 of file CAMsg.cpp.

References m_strLogFile, MSG_COMPRESSED_FILE, MSG_FILE, and pMsg.

Referenced by setLogOptions().

{
  const char* strLogAtPath = " at path '%s'";
  char* strLogFile = NULL;
  
  
  if ((opt & MSG_FILE) == MSG_FILE || (opt & MSG_COMPRESSED_FILE) == MSG_COMPRESSED_FILE)
  {
    if (pMsg->m_strLogFile != NULL)
    {
      strLogFile = new char[strlen(strLogAtPath) + strlen(pMsg->m_strLogFile) + 1];
      sprintf(strLogFile, strLogAtPath, pMsg->m_strLogFile);
    }
  }
  if (strLogFile == NULL)
  {
    strLogFile = new char[1];
    strLogFile[0] = '\0';
  }
  return strLogFile;
}
static SINT32 CAMsg::init ( ) [inline, static]

Definition at line 66 of file CAMsg.hpp.

References CAMsg(), E_SUCCESS, and pMsg.

Referenced by main().

      {
          if (pMsg == NULL)
          {
            pMsg=new CAMsg();
          }
          return E_SUCCESS;
      }

Here is the call graph for this function:

Open a log, where the logged messages are store encrypted.

The file format is as follows: NEWLINE "----Start of EncryptionKey----" NEWLINE 128 random bytes (BASE64 encoded of RSA encrpyted block) which are used as sym key (16 bytes starting form 50. byte) and IV (next 16 bytes) NEWLINE "-----End of EncryptionKey-----" NEWLINE encrpyted messages

The message is encrypted using AES-128-OFB.

Definition at line 489 of file CAMsg.cpp.

References E_SUCCESS, E_UNKNOWN, CABase64::encode(), CAASymCipher::encrypt(), FILENAME_ENCRYPTEDLOG, CACmdLnOptions::getLogEncryptionKey(), CALibProxytest::getOptions(), getRandom(), S_LOGENCCIPHER::iv, S_LOGENCCIPHER::iv_off, m_hFileEncrypted, m_pCipher, S_LOGENCCIPHER::oKey, pMsg, and CAASymCipher::setPublicKey().

Referenced by CACmdLnOptions::initLogging().

  {
    CACertificate* pCert=CALibProxytest::getOptions()->getLogEncryptionKey();
    if(pCert==NULL)
      return E_UNKNOWN;
    CAASymCipher oRSA;
    SINT32 ret=oRSA.setPublicKey(pCert);
    delete pCert;
    pCert = NULL;
    if(ret!=E_SUCCESS)
      return E_UNKNOWN;
    UINT8 buff[1024];
    if(CALibProxytest::getOptions()->getEncryptedLogDir(buff,1024)!=E_SUCCESS)
      if(CALibProxytest::getOptions()->getLogDir(buff,1024)!=E_SUCCESS)
        return E_UNKNOWN;
    strcat((char*)buff,FILENAME_ENCRYPTEDLOG);
    pMsg->m_hFileEncrypted=open((char*)buff,O_APPEND|O_CREAT|O_WRONLY|O_LARGEFILE|O_BINARY,S_IREAD|S_IWRITE);
    if(pMsg->m_hFileEncrypted<=0)
      {
        pMsg->m_hFileEncrypted=-1;
        return E_UNKNOWN;
      }
    //create sym enc key and write it to the file (enc with pub enc key)
    write(pMsg->m_hFileEncrypted,"\n----Start of EncryptionKey----\n",32);
    UINT8 keyandiv[128];
    getRandom(keyandiv,128);
    keyandiv[0]&=0x7F;
    pMsg->m_pCipher=new t_LogEncCipher;
    AES_set_encrypt_key(keyandiv+50,128,&pMsg->m_pCipher->oKey);
    memcpy(pMsg->m_pCipher->iv,keyandiv+66,16);
    pMsg->m_pCipher->iv_off=0;
    UINT8 out[255];
    UINT32 outlen=255;
    oRSA.encrypt(keyandiv,keyandiv);
    CABase64::encode(keyandiv,128,out,&outlen);
    write(pMsg->m_hFileEncrypted,out,outlen);
    write(pMsg->m_hFileEncrypted,"-----End of EncryptionKey-----\n",31);
    return E_SUCCESS;
  }

Here is the call graph for this function:

SINT32 CAMsg::openLog ( UINT32  type) [private]

Definition at line 414 of file CAMsg.cpp.

References E_FILE_OPEN, E_SUCCESS, E_UNKNOWN, FILENAME_INFOLOG, FILENAME_INFOLOG_GZ, GET_NET_ERROR, CALibProxytest::getOptions(), m_alreadyOpened, m_hFileInfo, m_NrOfWrites, m_strLogDir, m_strLogFile, MSG_COMPRESSED_FILE, MSG_FILE, MSG_LOG, rotateLog(), SET_NET_ERROR, and setMaxLogFileSize().

Referenced by printMsg(), and setLogOptions().

  {
        if ((type & MSG_LOG) == MSG_LOG)
        {
#ifndef _WIN32
      openlog("AnonMix",0,LOG_USER);
#endif
        }
#ifdef COMPRESSED_LOGS
        if ((type & MSG_COMPRESSED_FILE) == MSG_COMPRESSED_FILE)
        {
      char logdir[255];
      char buff[1024];
      if(CALibProxytest::getOptions()->getLogDir((UINT8*)logdir,255)!=E_SUCCESS)
        return E_UNKNOWN;
      strcpy(buff,logdir);
      strcat(buff,FILENAME_INFOLOG_GZ);
      tmpHandle=open(buff,O_APPEND|O_CREAT|O_WRONLY,S_IREAD|S_IWRITE);
      if (tmpHandle == -1)
      {
        return E_FILE_OPEN;
      }
      m_gzFileInfo=gzdopen(tmpHandle,"wb9");
      if(m_gzFileInfo==NULL)
      {
        SINT32 iError = GET_NET_ERROR;
        close(tmpHandle);
        SET_NET_ERROR(iError);
        return E_FILE_OPEN;
      }
      }
#endif
    else if ((type & MSG_FILE) == MSG_FILE)
        {
          if(CALibProxytest::getOptions()->getLogDir((UINT8*)m_strLogFile,1024)!=E_SUCCESS)
          {
            return E_UNKNOWN;
          }
          m_strLogDir = new char[strlen(m_strLogFile) + 1];
          strcpy(m_strLogDir, m_strLogFile);
          strcat(m_strLogFile,FILENAME_INFOLOG);
          if(CALibProxytest::getOptions()->getMaxLogFileSize()>0)
          {
            if(m_alreadyOpened)
            {
              rotateLog();
            }

            setMaxLogFileSize(CALibProxytest::getOptions()->getMaxLogFileSize());
            m_alreadyOpened = true;
          }
          m_NrOfWrites=0;
          m_hFileInfo=open(m_strLogFile,O_APPEND|O_CREAT|O_WRONLY|O_NONBLOCK|O_LARGEFILE,S_IREAD|S_IWRITE);
          if (m_hFileInfo == -1)
          {
            return E_FILE_OPEN;
          }
        }
    return E_SUCCESS;
  }

Here is the call graph for this function:

SINT32 CAMsg::printMsg ( UINT32  typ,
const char *  format,
  ... 
) [static]

Definition at line 225 of file CAMsg.cpp.

References closeLog(), E_SUCCESS, E_UNKNOWN, filesize64(), isGreater64(), isZero64(), S_LOGENCCIPHER::iv, S_LOGENCCIPHER::iv_off, CAMutex::lock(), LOG_ENCRYPTED, m_hFileEncrypted, m_hFileInfo, m_logLevel, m_maxLogFileSize, m_NrOfWrites, m_pCipher, m_pcsPrint, m_strMsgBuff, m_strMsgTypes, m_uLogType, MAX_MSG_SIZE, MSG_COMPRESSED_FILE, MSG_FILE, MSG_LOG, MSG_STDOUT, S_LOGENCCIPHER::oKey, openLog(), pMsg, STRMSGTYPES_SIZE, and CAMutex::unlock().

Referenced by CAAccountingDBInterface::__checkCountAllQuery(), CAAccountingDBInterface::__clearAccountStatus(), CAAccountingInstance::__commitSettlementToDatabase(), CAAccountingDBInterface::__deleteCC(), CAAccountingDBInterface::__getAccountStatus(), CAAccountingDBInterface::__getCostConfirmation(), CAAccountingDBInterface::__getPrepaidAmount(), CAAccountingDBInterface::__getUnsettledCostConfirmations(), CAAccountingInstance::__handleSettleResult(), CAAccountingInstance::__newSettlementTransaction(), CAAccountingDBInterface::__storeAccountStatus(), CAAccountingDBInterface::__storeCostConfirmation(), CAAccountingDBInterface::__storePrepaidAmount(), CASocket::accept(), CAQueue::add(), CAFirstMixChannelList::addChannel(), CACmdLnOptions::addMixIdToMixInfo(), CAThreadPool::addRequest(), TermsAndConditions::addTranslation(), CACmdLnOptions::appendMixInfo_internal(), CAMix::appendTermsAndConditionsExtension(), CAAccountingControlChannel::CAAccountingControlChannel(), CAAccountingInstance::CAAccountingInstance(), CAAccountingSettleThread::CAAccountingSettleThread(), CAReplayControlChannel::CAReplayControlChannel(), CAReplayCtrlChannelMsgProc::CAReplayCtrlChannelMsgProc(), CAAccountingInstance::cascadeMatchesCC(), CAMix::checkCompatibility(), CAAccountingDBInterface::checkConnectionStatus(), checkSizesOfBaseTypes(), CALastMix::clean(), CAFirstMix::clean(), CALibProxytest::cleanup(), cleanup(), CAAccountingDBInterface::cleanup(), CAAccountingInstance::cleanupTableEntry(), CATempIPBlockList::cleanupThreadMainLoop(), CASocket::close(), CAFirstMixA::closeConnection(), CASocket::connect(), CAMiddleMix::connectToNextMix(), CAFirstMix::connectToNextMix(), CASocket::create(), CACmdLnOptions::createSockets(), CATLSClientSocket::doTLSConnect(), CAFirstMix::doUserLogin_internal(), CAAccountingInstance::finishLoginProcess(), fm_loopAcceptUsers(), fm_loopReadFromMix(), fm_loopSendToMix(), CAAccountingDBInterface::getConnection(), CAXMLPriceCert::getInstance(), CACmdLnOptions::getMixXml(), CAAccountingInstance::getNrOfUsers(), CAInfoService::getPaymentInstance(), CAAccountingInstance::getPrepaidBytes(), CACertificate::getRawSubjectKeyIdentifier(), CACertificate::getSubjectKeyIdentifier(), CASignature::getVerifyKey(), CAAccountingInstance::handleAccountCertificate_internal(), CAAccountingInstance::handleChallengeResponse_internal(), CAAccountingInstance::handleCostConfirmation_internal(), CAAccountingInstance::handleJapPacket_internal(), CAFirstMix::handleTermsAndConditionsExtension(), CAFirstMix::handleTermsAndConditionsLogin(), CAInfoService::InfoLoop(), CALocalProxy::init(), CAMiddleMix::init(), CALastMix::init(), CAAccountingDBInterface::init(), CAFirstMix::init(), CAAccountingBIInterface::initBIConnection(), CAFirstMix::initCountryStats(), CAAccountingDBInterface::initDBConnection(), CACmdLnOptions::initLogging(), CAMix::initMixCascadeInfo(), CALocalProxy::initOnce(), CAMiddleMix::initOnce(), CALastMix::initOnce(), CAMix::initOnce(), CAFirstMix::initOnce(), CAIPList::insertIP(), integrateDOMNode(), CACmdLnOptions::invokeOptionSetters(), iplist_loopDoLogCountries(), isAllowedToPassRestrictions(), CACertificate::isValid(), CAThread::join(), CASocket::listen(), lm_loopLog(), lm_loopReadFromMix(), lm_loopSendToMix(), logMemoryUsage(), CALastMixA::loop(), CAFirstMixB::loop(), CAFirstMixA::loop(), CALastMixB::loop(), CALocalProxy::loop(), CAMiddleMix::loop(), main(), CAAccountingSettleThread::mainLoop(), CAAccountingInstance::makeInitialCCRequest(), CADatabase::measurePerformance(), CAReplayDatabase::measurePerformance(), mm_loopReadFromMixAfter(), mm_loopReadFromMixBefore(), mm_loopSendToMixAfter(), mm_loopSendToMixBefore(), CADatabase::nextClock(), CAReplayDatabase::nextClock(), CACmdLnOptions::parse(), CAHttpClient::parseHTTPHeader(), CAFirstMixChannelList::popTimeoutEntry_internal(), CAAccountingInstance::prepareCCRequest(), CAReplayCtrlChannelMsgProc::proccessGotTimestamp(), CASyncControlChannel::proccessMessage(), CASyncControlChannel::proccessMessageComplete(), CAChain::processDownstream(), CAAccountingInstance::processJapMessage(), CALocalProxy::processKeyExchange(), CAMiddleMix::processKeyExchange(), CALastMix::processKeyExchange(), CAFirstMix::processKeyExchange(), CAAccountingInstance::processThread(), CACmdLnOptions::processXmlConfiguration(), CAReplayControlChannel::processXMLMessage(), CAAccountingControlChannel::processXMLMessage(), CAReplayCtrlChannelMsgProc::propagateCurrentReplayTimestamp(), CACmdLnOptions::readXmlConfiguration(), CATLSClientSocket::receive(), CASocket::receive(), CAMuxSocket::receive(), CALastMix::reconfigure(), CAFirstMix::reconfigure(), CALastMixB::reconfigureMix(), Hashtable::rehash(), CAAccountingDBInterface::releaseConnection(), CACertificate::removeColons(), CAFirstMixChannelList::removeFromTimeoutList(), CAIPList::removeIP(), CAAccountingInstance::returnKickout(), CAAccountingInstance::returnPrepareKickout(), CASocketGroup::select(), CATLSClientSocket::send(), CASocket::send(), CAMuxSocket::send(), CAAccountingInstance::sendAILoginConfirmation(), CAInfoService::sendCascadeHelo(), CAAccountingInstance::sendCCRequest(), CASocket::sendFully(), CASocket::sendFullyTimeOut(), CAHttpClient::sendGetRequest(), CAAccountingInstance::sendInitialCCRequest(), CAControlChannelDispatcher::sendMessages(), CAInfoService::sendMixHelo(), CAHttpClient::sendPostRequest(), CAInfoService::sendStatus(), CASocket::sendTimeOut(), CACmdLnOptions::setAccountingDatabase(), CAFirstMixChannelList::setDelayParameters(), CACmdLnOptions::setDynamicMix(), CASocket::setKeepAlive(), CAFirstMixChannelList::setKickoutForced_internal(), CACmdLnOptions::setListenerInterfaces(), CACmdLnOptions::setLoggingOptions(), setLogOptions(), CACmdLnOptions::setMixCertificateVerification(), CACmdLnOptions::setNextMix(), CACmdLnOptions::setNextMixCertificate(), CACmdLnOptions::setNrOfFileDescriptors(), CACmdLnOptions::setOwnCertificate(), CACmdLnOptions::setPaymentInstance(), CAAccountingBIInterface::setPIServerConfiguration(), CACmdLnOptions::setPrepaidInterval(), CACmdLnOptions::setPrevMix(), CACmdLnOptions::setPriceCertificate(), CACmdLnOptions::setRessourceOptions(), CACmdLnOptions::setServerMonitoring(), CASignature::setSignKey(), CACmdLnOptions::setTargetInterfaces(), CALastMix::setTargets(), CACmdLnOptions::setTermsAndConditions(), CACmdLnOptions::setTermsAndConditionsList(), CACmdLnOptions::setTermsAndConditionsTemplates(), CAAccountingBIInterface::settle(), CAAccountingBIInterface::settleAll(), CAAccountingInstance::settlementTransaction(), CACmdLnOptions::setTrustedRootCertificates(), CACmdLnOptions::setUserID(), CAXMLBI::setValues(), CAXMLErrorMessage::setValues(), CAXMLPriceCert::setValues(), CASignature::setVerifyKey(), CAFirstMixA::shutDown(), signal_interrupt(), signal_segv(), signal_term(), CAMultiSignature::signXML(), SIGUSR1_handler(), SIGUSR2_handler(), CALocalProxy::start(), CAMix::start(), CAInfoService::start(), CAThread::start(), CAAccountingBIInterface::terminateBIConnection(), threadReConfigure(), CAXMLPriceCert::toXmlElement(), CAFirstMix::updateCountryStats(), CACertificate::verify(), CACertStore::verifyMixCert(), CAMultiSignature::verifyXML(), CAAccountingControlChannel::~CAAccountingControlChannel(), CAAccountingInstance::~CAAccountingInstance(), CAChain::~CAChain(), CAReplayCtrlChannelMsgProc::~CAReplayCtrlChannelMsgProc(), and CATempIPBlockList::~CATempIPBlockList().

  {
    if(pMsg != NULL)
    {
      pMsg->m_pcsPrint->lock();
      va_list ap;
      va_start(ap,format);
      SINT32 ret=E_SUCCESS;
      
      //Date is: yyyy/mm/dd-hh:mm:ss   -- the size is: 19
      time_t currtime=time(NULL);
      strftime(pMsg->m_strMsgBuff+1,255,"%Y/%m/%d-%H:%M:%S",localtime(&currtime));
      switch(type)
        {
          case LOG_DEBUG:
            if (pMsg->m_logLevel != LOG_DEBUG)
            {
              ret = E_UNKNOWN;
            }
            strcat(pMsg->m_strMsgBuff,pMsg->m_strMsgTypes[3]);
          break;
          case LOG_INFO:
            if (pMsg->m_logLevel == LOG_WARNING || pMsg->m_logLevel == LOG_ERR || pMsg->m_logLevel == LOG_CRIT)
            {
              ret = E_UNKNOWN;
            }
            strcat(pMsg->m_strMsgBuff,pMsg->m_strMsgTypes[2]);
          break;
          case LOG_CRIT:
            strcat(pMsg->m_strMsgBuff,pMsg->m_strMsgTypes[1]);
          break;
          case LOG_ERR:
            if (pMsg->m_logLevel == LOG_CRIT)
            {
              ret = E_UNKNOWN;
            }
            strcat(pMsg->m_strMsgBuff,pMsg->m_strMsgTypes[0]);
          break;
          case LOG_ENCRYPTED:
            strcat(pMsg->m_strMsgBuff,pMsg->m_strMsgTypes[4]);
          break;
          case LOG_WARNING:
            if (pMsg->m_logLevel == LOG_ERR || pMsg->m_logLevel == LOG_CRIT)
            {
              ret = E_UNKNOWN;
            }
            strcat(pMsg->m_strMsgBuff,pMsg->m_strMsgTypes[5]);
          break;
          default:
            va_end(ap);
            pMsg->m_pcsPrint->unlock();
            return E_UNKNOWN;
        }
  #ifdef HAVE_VSNPRINTF
      vsnprintf(pMsg->m_strMsgBuff+20+STRMSGTYPES_SIZE,MAX_MSG_SIZE,format,ap);
  #else
      trio_vsnprintf(pMsg->m_strMsgBuff+20+STRMSGTYPES_SIZE,MAX_MSG_SIZE,format,ap);
  #endif
      va_end(ap);
      if (ret != E_SUCCESS)
      {
        pMsg->m_pcsPrint->unlock();
        return ret;
      }
      if(type==LOG_ENCRYPTED)
      {
        ret=strlen(pMsg->m_strMsgBuff);
        if( pMsg->m_pCipher==NULL)
        {
          ret=E_UNKNOWN;
        }
        else
        {
          UINT8 bp[MAX_MSG_SIZE];
          AES_ofb128_encrypt((UINT8*)pMsg->m_strMsgBuff,
                              bp,ret,
                              &(pMsg->m_pCipher->oKey),
                              pMsg->m_pCipher->iv,
                              &(pMsg->m_pCipher->iv_off));
          if(write(pMsg->m_hFileEncrypted,bp,ret)!=ret)
            ret=E_UNKNOWN;
        }
      }
      else
        {
              if ((pMsg->m_uLogType & MSG_LOG) == MSG_LOG)
              {
  #ifndef _WIN32
            syslog(type,pMsg->m_strMsgBuff);
  #endif
              }
  #ifdef COMPRESSED_LOGS
              if ((pMsg->m_uLogType & MSG_COMPRESSED_FILE) == MSG_COMPRESSED_FILE)
              {
                if(pMsg->m_gzFileInfo!=NULL)
                {
                  if(gzwrite(pMsg->m_gzFileInfo,pMsg->m_strMsgBuff,strlen(pMsg->m_strMsgBuff))==-1)
                    ret=E_UNKNOWN;
                }
              }
  #endif
              else if ((pMsg->m_uLogType & MSG_FILE) == MSG_FILE)
              {
/*                if(pMsg->m_hFileInfo==-1)
                  {
                    pMsg->m_hFileInfo=open(pMsg->m_strLogFile,O_APPEND|O_CREAT|O_WRONLY|O_NONBLOCK|O_LARGEFILE|O_SYNC,S_IREAD|S_IWRITE);
                  }
*///                if(pMsg->m_hFileInfo!=-1)
//                  {
      #ifdef PSEUDO_LOG
                    char buff[255];
                    sprintf(buff,"%.15s mix AnonMix: ",ctime(&currtime)+4);
                    write(pMsg->m_hFileInfo,buff,strlen(buff));
      #endif
                    if(write(pMsg->m_hFileInfo,pMsg->m_strMsgBuff,strlen(pMsg->m_strMsgBuff))==-1)
                      ret=E_UNKNOWN;
                    pMsg->m_NrOfWrites++;
                    if( //(pMsg->m_NrOfWrites > 10000) &&
                      !isZero64(pMsg->m_maxLogFileSize) &&
                      isGreater64(filesize64(pMsg->m_hFileInfo), pMsg->m_maxLogFileSize))
                      {
                        pMsg->closeLog();
                        pMsg->openLog(pMsg->m_uLogType);
                      }
//                  }
              }
              if ((pMsg->m_uLogType & MSG_STDOUT) == MSG_STDOUT)
              {
                printf("%s",pMsg->m_strMsgBuff);
              }
        }
      pMsg->m_pcsPrint->unlock();
      return ret;
    }
    else
    {
      printf("Warning logger is not active!\n");
      return E_UNKNOWN;
    }
  }

Here is the call graph for this function:

SINT32 CAMsg::rotateLog ( ) [private]

Definition at line 391 of file CAMsg.cpp.

References E_SUCCESS, CACmdLnOptions::getMaxLogFiles(), CALibProxytest::getOptions(), m_lastLogFileNumber, m_strLogFile, m_uLogType, MSG_COMPRESSED_FILE, MSG_FILE, and pMsg.

Referenced by openLog().

{
    if ((pMsg->m_uLogType & MSG_COMPRESSED_FILE) == MSG_COMPRESSED_FILE)
    {
      // TODO
    }
    else if ((pMsg->m_uLogType & MSG_FILE) == MSG_FILE)
    {

      char logFileSaveName[1026];
      memset(logFileSaveName, 0, 1026);
      //memcpy(logFileSave, m_strMsgBuff, 1024);
      snprintf(logFileSaveName, 1025, "%s%u", m_strLogFile, m_lastLogFileNumber);
      m_lastLogFileNumber = (m_lastLogFileNumber+1) % CALibProxytest::getOptions()->getMaxLogFiles();
      rename(m_strLogFile, logFileSaveName);
      /*if(m_hFileInfo!=-1)
        close(m_hFileInfo);
      m_hFileInfo=-1;*/
    }

  return E_SUCCESS;
}

Here is the call graph for this function:

SINT32 CAMsg::setLogLevel ( UINT32  a_logLevel) [static]

Definition at line 127 of file CAMsg.cpp.

References E_SUCCESS, E_UNKNOWN, m_logLevel, and pMsg.

Referenced by CACmdLnOptions::initLogging().

{
  if (a_logLevel == LOG_DEBUG ||
    a_logLevel == LOG_INFO ||
    a_logLevel == LOG_WARNING ||
    a_logLevel == LOG_ERR ||
    a_logLevel == LOG_CRIT)
  {
    pMsg->m_logLevel = a_logLevel;
    return E_SUCCESS;
  }
  return E_UNKNOWN;
}
SINT32 CAMsg::setLogOptions ( UINT32  options) [static]

Definition at line 141 of file CAMsg.cpp.

References closeLog(), createLogDirMessage(), createLogFileMessage(), E_FILE_OPEN, E_SUCCESS, GET_NET_ERROR, GET_NET_ERROR_STR, m_uLogType, MSG_COMPRESSED_FILE, MSG_FILE, MSG_LOG, openLog(), pMsg, and printMsg().

Referenced by CACmdLnOptions::initLogging().

    {
      SINT32 ret; 
      const char* strLogOpened = "Message log opened%s%s.\n";
      const char* strLogErrorMsg = "Could not open message log%s%s!%s Do you have write permissions?%s\n";
      const char* strReasonMsg = " Reason: %s (%u)";
      char* strLogFile = NULL;
      char* strLogDir = NULL;
      char* strReason = NULL;
      char* strBuff;
      const char* strLogType = "";
  

      if(pMsg->m_uLogType==opt)
      {
          return E_SUCCESS;
      }


      if (opt == MSG_LOG)
      {
        strLogType = " as Syslog";
      }
      else if ((opt & MSG_LOG) == MSG_LOG)
      {
        strLogType = " as Syslog and";
      }

      if ((opt & MSG_FILE) == MSG_FILE)
      {
        strLogType = " as file";
      }
      else if ((opt & MSG_COMPRESSED_FILE) == MSG_COMPRESSED_FILE)
      {
        strLogType = " as compressed file";
      }
      
      

      if((ret = pMsg->openLog(opt))==E_SUCCESS)
      {
        strLogFile = pMsg->createLogFileMessage(opt);
        strBuff = new char[strlen(strLogOpened) + strlen(strLogType) + strlen(strLogFile) + 1];
        sprintf(strBuff, strLogOpened, strLogType, strLogFile);
        delete[] strLogFile;
        printMsg(LOG_DEBUG, strBuff);
        delete[] strBuff;

        pMsg->closeLog(); //closes the OLD Log!
        pMsg->m_uLogType=opt;

        
        return E_SUCCESS;
      }
      

      strLogFile = pMsg->createLogFileMessage(opt);
      
      strLogDir = pMsg->createLogDirMessage(opt);

      if (ret == E_FILE_OPEN)
      {
        strReason = new char[strlen(strReasonMsg) + strlen(GET_NET_ERROR_STR(GET_NET_ERROR)) + 5 + 1];
        sprintf(strReason, strReasonMsg, GET_NET_ERROR_STR(GET_NET_ERROR), GET_NET_ERROR);
      }
      else
      {
        strReason = new char[1];
        strReason[0] = '\0';
      }

      strBuff = new char[strlen(strLogErrorMsg) + strlen(strLogType) + strlen(strLogFile) + strlen(strReason) + strlen(strLogDir) + 1];
    
      sprintf(strBuff, strLogErrorMsg, strLogType, strLogFile, strReason, strLogDir);
      //snprintf(strBuff, strlen(strLogErrorMsg) + strlen(strLogFile) + strlen(strReason) + 1,  strLogErrorMsg, strLogFile, strReason);
      delete[] strLogFile;
      delete[] strReason;

      printMsg(LOG_CRIT, strBuff);

      delete[] strBuff;
      return ret;
    }

Here is the call graph for this function:

static SINT32 CAMsg::setMaxLogFileSize ( UINT64  size) [inline, static]

Definition at line 86 of file CAMsg.hpp.

References E_SUCCESS, E_UNKNOWN, m_maxLogFileSize, pMsg, and set64().

Referenced by openLog().

        {
          if(pMsg!=NULL)
            {
              set64(pMsg->m_maxLogFileSize,size);
              return E_SUCCESS;
            }
          return E_UNKNOWN;
        }

Here is the call graph for this function:


Member Data Documentation

bool CAMsg::m_alreadyOpened [private]

Definition at line 114 of file CAMsg.hpp.

Referenced by CAMsg(), and openLog().

int CAMsg::m_hFileEncrypted [private]

Definition at line 115 of file CAMsg.hpp.

Referenced by CAMsg(), closeEncryptedLog(), openEncryptedLog(), and printMsg().

int CAMsg::m_hFileInfo [private]

Definition at line 116 of file CAMsg.hpp.

Referenced by CAMsg(), closeLog(), openLog(), and printMsg().

Definition at line 113 of file CAMsg.hpp.

Referenced by CAMsg(), and rotateLog().

Definition at line 112 of file CAMsg.hpp.

Referenced by CAMsg(), printMsg(), and setLogLevel().

Definition at line 104 of file CAMsg.hpp.

Referenced by CAMsg(), printMsg(), and setMaxLogFileSize().

Definition at line 105 of file CAMsg.hpp.

Referenced by openLog(), and printMsg().

Definition at line 125 of file CAMsg.hpp.

Referenced by CAMsg(), closeEncryptedLog(), openEncryptedLog(), and printMsg().

Definition at line 121 of file CAMsg.hpp.

Referenced by CAMsg(), printMsg(), and ~CAMsg().

char* CAMsg::m_strLogDir [private]

Definition at line 119 of file CAMsg.hpp.

Referenced by createLogDirMessage(), and openLog().

char* CAMsg::m_strLogFile [private]

Definition at line 118 of file CAMsg.hpp.

Referenced by CAMsg(), createLogFileMessage(), openLog(), rotateLog(), and ~CAMsg().

char* CAMsg::m_strMsgBuff [private]

Definition at line 117 of file CAMsg.hpp.

Referenced by CAMsg(), printMsg(), and ~CAMsg().

const char *const CAMsg::m_strMsgTypes = {", error ] ",", critical] ",", info ] ",", debug ] ",", special ] ",", warning ] "} [static, private]

Definition at line 120 of file CAMsg.hpp.

Referenced by printMsg().

Definition at line 111 of file CAMsg.hpp.

Referenced by CAMsg(), closeLog(), printMsg(), rotateLog(), and setLogOptions().

CAMsg * CAMsg::pMsg = NULL [static, private]

The documentation for this class was generated from the following files: