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

#include <CAMsg.hpp>

Collaboration diagram for CAMsg:

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 const char *const getLogLevelStr ()
 
static SINT32 setMaxLogFileSize (UINT64 size)
 
static SINT32 printMsg (UINT32 typ, const char *format,...)
 Writes a given message to the log. More...
 
static SINT32 openEncryptedLog ()
 Open a log, where the logged messages are store encrypted. More...
 
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 ms_arStrLogLevels [5] = { "CRITICAL","ERROR","WARNING","INFO","DEBUG" }
 
static const char *const m_strMsgTypes [6] ={", error ] ",", critical] ",", info ] ",", debug ] ",", special ] ",", warning ] "}
 

Detailed Description

Definition at line 61 of file CAMsg.hpp.

Constructor & Destructor Documentation

◆ CAMsg()

CAMsg::CAMsg ( )
private

Definition at line 49 of file CAMsg.cpp.

50  {
51  m_pcsPrint=new CAMutex();
52  m_logLevel = LOG_DEBUG;
56  m_hFileInfo=-1;
58  m_strLogFile=new char[1024];
59  m_strMsgBuff[0]='[';
60 #ifdef COMPRESSED_LOGS
61  m_gzFileInfo=NULL;
62 #endif
63  m_pCipher=NULL;
65  m_alreadyOpened = false;
66  }
#define MAX_MSG_SIZE
Definition: CAMsg.cpp:41
#define STRMSGTYPES_SIZE
Definition: CAMsg.cpp:46
#define MSG_STDOUT
Definition: CAMsg.hpp:34
void setZero64(UINT64 &op1)
Definition: CAUtil.hpp:355
char * m_strLogFile
Definition: CAMsg.hpp:122
bool m_alreadyOpened
Definition: CAMsg.hpp:118
SINT64 m_maxLogFileSize
Definition: CAMsg.hpp:108
t_LogEncCipher * m_pCipher
Definition: CAMsg.hpp:129
UINT32 m_lastLogFileNumber
Definition: CAMsg.hpp:117
int m_hFileEncrypted
Definition: CAMsg.hpp:119
char * m_strMsgBuff
Definition: CAMsg.hpp:121
CAMutex * m_pcsPrint
Definition: CAMsg.hpp:125
int m_hFileInfo
Definition: CAMsg.hpp:120
UINT32 m_uLogType
Definition: CAMsg.hpp:115
UINT32 m_logLevel
Definition: CAMsg.hpp:116

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~CAMsg()

CAMsg::~CAMsg ( )

Definition at line 68 of file CAMsg.cpp.

69  {
70  closeLog();
71 #ifndef ONLY_LOCAL_PROXY
73 #endif
74  delete[] m_strMsgBuff;
75  m_strMsgBuff = NULL;
76  delete[] m_strLogFile;
77  m_strLogFile = NULL;
78  delete m_pcsPrint;
79  m_pcsPrint = NULL;
80  }
SINT32 closeLog()
Definition: CAMsg.cpp:397
static SINT32 closeEncryptedLog()
Definition: CAMsg.cpp:560

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

Here is the call graph for this function:

Member Function Documentation

◆ cleanup()

static SINT32 CAMsg::cleanup ( )
inlinestatic

Definition at line 77 of file CAMsg.hpp.

78  {
79  if (pMsg != NULL)
80  {
81  pMsg->closeLog();
82  }
83  delete pMsg;
84  pMsg = NULL;
85  return E_SUCCESS;
86  }
static CAMsg * pMsg
Definition: CAMsg.hpp:65
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2

References closeLog(), E_SUCCESS, and pMsg.

Referenced by CALibProxytest::cleanup(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ closeEncryptedLog()

SINT32 CAMsg::closeEncryptedLog ( )
static

Definition at line 560 of file CAMsg.cpp.

561  {
562  if(pMsg->m_hFileEncrypted>=0)
563  {
564  close(pMsg->m_hFileEncrypted);
565  }
566  delete pMsg->m_pCipher;
567  pMsg->m_pCipher=NULL;
569  return E_SUCCESS;
570  }

References E_SUCCESS, m_hFileEncrypted, m_pCipher, and pMsg.

Referenced by ~CAMsg().

Here is the caller graph for this function:

◆ closeLog()

SINT32 CAMsg::closeLog ( )
private

Definition at line 397 of file CAMsg.cpp.

398  {
399  if ((pMsg->m_uLogType & MSG_LOG) == MSG_LOG)
400  {
401 #ifndef _WIN32
402  ::closelog();
403 #endif
404  }
405 #ifdef COMPRESSED_LOGS
407  {
408  if(m_gzFileInfo!=NULL)
409  gzclose(m_gzFileInfo);
410  m_gzFileInfo=NULL;
411  }
412 #endif
413  else if ((pMsg->m_uLogType & MSG_FILE) == MSG_FILE)
414  {
415  if(m_hFileInfo!=-1)
416  close(m_hFileInfo);
417  m_hFileInfo=-1;
418  }
419  return E_SUCCESS;
420  }
#define MSG_FILE
Definition: CAMsg.hpp:36
#define MSG_LOG
Definition: CAMsg.hpp:35
#define MSG_COMPRESSED_FILE
Definition: CAMsg.hpp:37

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

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

Here is the caller graph for this function:

◆ createLogDirMessage()

char * CAMsg::createLogDirMessage ( UINT32  opt)
private

Definition at line 104 of file CAMsg.cpp.

105 {
106  const char* strLogAtPath = " Please also check if the directory '%s' exists and create or change it if it does not.";
107  char* strLogFile = NULL;
108 
109 
110  if ((opt & MSG_FILE) == MSG_FILE || (opt & MSG_COMPRESSED_FILE) == MSG_COMPRESSED_FILE)
111  {
112  if (pMsg->m_strLogDir != NULL)
113  {
114  strLogFile = new char[strlen(strLogAtPath) + strlen(pMsg->m_strLogDir) + 1];
115  sprintf(strLogFile, strLogAtPath, pMsg->m_strLogDir);
116  }
117  }
118  if (strLogFile == NULL)
119  {
120  strLogFile = new char[1];
121  strLogFile[0] = '\0';
122  }
123  return strLogFile;
124 }
char * m_strLogDir
Definition: CAMsg.hpp:123

References m_strLogDir, MSG_COMPRESSED_FILE, MSG_FILE, and pMsg.

Referenced by setLogOptions().

Here is the caller graph for this function:

◆ createLogFileMessage()

char * CAMsg::createLogFileMessage ( UINT32  opt)
private

Definition at line 82 of file CAMsg.cpp.

83 {
84  const char* strLogAtPath = " at path '%s'";
85  char* strLogFile = NULL;
86 
87 
88  if ((opt & MSG_FILE) == MSG_FILE || (opt & MSG_COMPRESSED_FILE) == MSG_COMPRESSED_FILE)
89  {
90  if (pMsg->m_strLogFile != NULL)
91  {
92  strLogFile = new char[strlen(strLogAtPath) + strlen(pMsg->m_strLogFile) + 1];
93  sprintf(strLogFile, strLogAtPath, pMsg->m_strLogFile);
94  }
95  }
96  if (strLogFile == NULL)
97  {
98  strLogFile = new char[1];
99  strLogFile[0] = '\0';
100  }
101  return strLogFile;
102 }

References m_strLogFile, MSG_COMPRESSED_FILE, MSG_FILE, and pMsg.

Referenced by setLogOptions().

Here is the caller graph for this function:

◆ getLogLevelStr()

const char *const CAMsg::getLogLevelStr ( )
static

Definition at line 143 of file CAMsg.cpp.

144  {
145  switch (pMsg->m_uLogType)
146  {
147  case LOG_CRIT:
148  return ms_arStrLogLevels[0];
149  case LOG_ERR:
150  return ms_arStrLogLevels[1];
151  case LOG_WARNING:
152  return ms_arStrLogLevels[2];
153  case LOG_INFO:
154  return ms_arStrLogLevels[3];
155  case LOG_DEBUG:
156  return ms_arStrLogLevels[4];
157  }
158  return NULL;
159  }
static const char *const ms_arStrLogLevels[5]
Definition: CAMsg.hpp:66

References m_uLogType, ms_arStrLogLevels, and pMsg.

Referenced by main().

Here is the caller graph for this function:

◆ init()

static SINT32 CAMsg::init ( )
inlinestatic

Definition at line 69 of file CAMsg.hpp.

70  {
71  if (pMsg == NULL)
72  {
73  pMsg=new CAMsg();
74  }
75  return E_SUCCESS;
76  }
CAMsg()
Definition: CAMsg.cpp:49

References CAMsg(), E_SUCCESS, and pMsg.

Referenced by CALibProxytest::init(), CACmdLnOptions::initLogging(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openEncryptedLog()

SINT32 CAMsg::openEncryptedLog ( )
static

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 520 of file CAMsg.cpp.

521  {
523  if(pCert==NULL)
524  return E_UNKNOWN;
525  CAASymCipher oRSA;
526  SINT32 ret=oRSA.setPublicKey(pCert);
527  delete pCert;
528  pCert = NULL;
529  if(ret!=E_SUCCESS)
530  return E_UNKNOWN;
531  UINT8 buff[1024];
532  if(CALibProxytest::getOptions()->getEncryptedLogDir(buff,1024)!=E_SUCCESS)
533  if(CALibProxytest::getOptions()->getLogDir(buff,1024)!=E_SUCCESS)
534  return E_UNKNOWN;
535  strcat((char*)buff,FILENAME_ENCRYPTEDLOG);
536  pMsg->m_hFileEncrypted=open((char*)buff,O_APPEND|O_CREAT|O_WRONLY|O_LARGEFILE|O_BINARY,S_IREAD|S_IWRITE);
537  if(pMsg->m_hFileEncrypted<=0)
538  {
540  return E_UNKNOWN;
541  }
542  //create sym enc key and write it to the file (enc with pub enc key)
543  myfilewrite(pMsg->m_hFileEncrypted, "\n----Start of EncryptionKey----\n", 32);
544  UINT8 keyandiv[128];
545  getRandom(keyandiv,128);
546  keyandiv[0]&=0x7F;
548  AES_set_encrypt_key(keyandiv+50,128,&pMsg->m_pCipher->oKey);
549  memcpy(pMsg->m_pCipher->iv,keyandiv+66,16);
550  pMsg->m_pCipher->iv_off=0;
551  UINT8 out[255];
552  UINT32 outlen=255;
553  oRSA.encrypt(keyandiv,keyandiv);
554  CABase64::encode(keyandiv,128,out,&outlen);
555  myfilewrite(pMsg->m_hFileEncrypted, out, outlen);
556  myfilewrite(pMsg->m_hFileEncrypted, "-----End of EncryptionKey-----\n", 31);
557  return E_SUCCESS;
558  }
#define FILENAME_ENCRYPTEDLOG
Definition: CAMsg.cpp:37
S_LOGENCCIPHER t_LogEncCipher
Definition: CAMsg.hpp:59
SINT32 getRandom(UINT32 *val)
Gets 32 random bits.
Definition: CAUtil.cpp:346
#define myfilewrite
Definition: StdAfx.h:493
#define O_LARGEFILE
Definition: StdAfx.h:635
#define S_IWRITE
Definition: StdAfx.h:491
#define S_IREAD
Definition: StdAfx.h:488
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
SINT32 encrypt(const UINT8 *from, UINT8 *to)
Encrypts exactly one block which is stored in from.
SINT32 setPublicKey(const CACertificate *pCert)
Sets the public key which is used for encryption to the contained in the provided certificate.
static SINT32 encode(const UINT8 *in, UINT32 len, UINT8 *out, UINT32 *outlen)
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
Definition: CABase64.cpp:102
CACertificate * getLogEncryptionKey()
Returns a certificate which contains a key which could be used for log encryption.
static CACmdLnOptions * getOptions()
#define O_BINARY
Definition: config.h:179
#define E_UNKNOWN
Definition: errorcodes.hpp:3
AES_KEY oKey
Definition: CAMsg.hpp:56
UINT8 iv[16]
Definition: CAMsg.hpp:54

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, myfilewrite, O_BINARY, O_LARGEFILE, S_LOGENCCIPHER::oKey, pMsg, S_IREAD, S_IWRITE, and CAASymCipher::setPublicKey().

Referenced by CACmdLnOptions::initLogging().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openLog()

SINT32 CAMsg::openLog ( UINT32  type)
private

Definition at line 445 of file CAMsg.cpp.

446  {
447  if ((type & MSG_LOG) == MSG_LOG)
448  {
449 #ifndef _WIN32
450  openlog("AnonMix",0,LOG_USER);
451 #endif
452  }
453 #ifdef COMPRESSED_LOGS
455  {
456  char logdir[255];
457  char buff[1024];
458  if(CALibProxytest::getOptions()->getLogDir((UINT8*)logdir,255)!=E_SUCCESS)
459  return E_UNKNOWN;
460  strcpy(buff,logdir);
461  strcat(buff,FILENAME_INFOLOG_GZ);
462  tmpHandle=open(buff,O_APPEND|O_CREAT|O_WRONLY,S_IREAD|S_IWRITE);
463  if (tmpHandle == -1)
464  {
465  return E_FILE_OPEN;
466  }
467  m_gzFileInfo=gzdopen(tmpHandle,"wb9");
468  if(m_gzFileInfo==NULL)
469  {
470  SINT32 iError = GET_NET_ERROR;
471  close(tmpHandle);
472  SET_NET_ERROR(iError);
473  return E_FILE_OPEN;
474  }
475  }
476 #endif
477  else if ((type & MSG_FILE) == MSG_FILE)
478  {
479  if(CALibProxytest::getOptions()->getLogDir((UINT8*)m_strLogFile,1024)!=E_SUCCESS)
480  {
481  return E_UNKNOWN;
482  }
483  m_strLogDir = new char[strlen(m_strLogFile) + 1];
484  strcpy(m_strLogDir, m_strLogFile);
486  if(CALibProxytest::getOptions()->getMaxLogFileSize()>0)
487  {
488  if(m_alreadyOpened)
489  {
490  rotateLog();
491  }
492 
493  setMaxLogFileSize(CALibProxytest::getOptions()->getMaxLogFileSize());
494  m_alreadyOpened = true;
495  }
496  m_NrOfWrites=0;
497  m_hFileInfo=open(m_strLogFile,O_APPEND|O_CREAT|O_WRONLY|O_NONBLOCK|O_LARGEFILE,S_IREAD|S_IWRITE);
498  if (m_hFileInfo == -1)
499  {
500  return E_FILE_OPEN;
501  }
502  }
503  return E_SUCCESS;
504  }
#define FILENAME_INFOLOG
Definition: CAMsg.cpp:38
#define FILENAME_INFOLOG_GZ
Definition: CAMsg.cpp:39
#define GET_NET_ERROR
Definition: StdAfx.h:469
#define SET_NET_ERROR(x)
Definition: StdAfx.h:470
UINT32 m_NrOfWrites
Definition: CAMsg.hpp:109
static SINT32 setMaxLogFileSize(UINT64 size)
Definition: CAMsg.hpp:90
SINT32 rotateLog()
Definition: CAMsg.cpp:422
#define E_FILE_OPEN
Definition: errorcodes.hpp:19
UINT8 type
Definition: typedefs.hpp:1

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, O_LARGEFILE, rotateLog(), S_IREAD, S_IWRITE, SET_NET_ERROR, setMaxLogFileSize(), and type.

Referenced by printMsg(), and setLogOptions().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ printMsg()

SINT32 CAMsg::printMsg ( UINT32  type,
const char *  format,
  ... 
)
static

Writes a given message to the log.

Parameters
typetype of the log message (debug,info warning, error)
formatformat string as in printf()

<return>E_SUCCESS, if log messages was successful written</return> <return>E_UNKNOWN, in case of some error</return>

Definition at line 251 of file CAMsg.cpp.

252  {
253  if (pMsg->m_uLogType == MSG_NOLOG)
254  {
255  return E_SUCCESS;
256  }
257 
258  if(pMsg != NULL)
259  {
260  pMsg->m_pcsPrint->lock();
261  va_list ap;
262  va_start(ap,format);
263  SINT32 ret=E_SUCCESS;
264 
265  //Date is: yyyy/mm/dd-hh:mm:ss -- the size is: 19
266  time_t currtime=time(NULL);
267  strftime(pMsg->m_strMsgBuff+1,255,"%Y/%m/%d-%H:%M:%S",localtime(&currtime));
268  switch(type)
269  {
270  case LOG_DEBUG:
271  if (pMsg->m_logLevel != LOG_DEBUG)
272  {
273  ret = E_UNKNOWN;
274  }
275  strcat(pMsg->m_strMsgBuff,pMsg->m_strMsgTypes[3]);
276  break;
277  case LOG_INFO:
278  if (pMsg->m_logLevel == LOG_WARNING || pMsg->m_logLevel == LOG_ERR || pMsg->m_logLevel == LOG_CRIT)
279  {
280  ret = E_UNKNOWN;
281  }
282  strcat(pMsg->m_strMsgBuff,pMsg->m_strMsgTypes[2]);
283  break;
284  case LOG_CRIT:
285  strcat(pMsg->m_strMsgBuff,pMsg->m_strMsgTypes[1]);
286  break;
287  case LOG_ERR:
288  if (pMsg->m_logLevel == LOG_CRIT)
289  {
290  ret = E_UNKNOWN;
291  }
292  strcat(pMsg->m_strMsgBuff,pMsg->m_strMsgTypes[0]);
293  break;
294  case LOG_ENCRYPTED:
295  strcat(pMsg->m_strMsgBuff,pMsg->m_strMsgTypes[4]);
296  break;
297  case LOG_WARNING:
298  if (pMsg->m_logLevel == LOG_ERR || pMsg->m_logLevel == LOG_CRIT)
299  {
300  ret = E_UNKNOWN;
301  }
302  strcat(pMsg->m_strMsgBuff,pMsg->m_strMsgTypes[5]);
303  break;
304  default:
305  va_end(ap);
306  pMsg->m_pcsPrint->unlock();
307  return E_UNKNOWN;
308  }
309  #ifdef HAVE_VSNPRINTF
310  vsnprintf(pMsg->m_strMsgBuff+20+STRMSGTYPES_SIZE,MAX_MSG_SIZE,format,ap);
311  #else
312  trio_vsnprintf(pMsg->m_strMsgBuff+20+STRMSGTYPES_SIZE,MAX_MSG_SIZE,format,ap);
313  #endif
314  va_end(ap);
315  if (ret != E_SUCCESS)
316  {
317  pMsg->m_pcsPrint->unlock();
318  return ret;
319  }
320  if(type==LOG_ENCRYPTED)
321  {
322  ret=strlen(pMsg->m_strMsgBuff);
323  if( pMsg->m_pCipher==NULL)
324  {
325  ret=E_UNKNOWN;
326  }
327  else
328  {
329  UINT8 bp[MAX_MSG_SIZE];
330  AES_ofb128_encrypt((UINT8*)pMsg->m_strMsgBuff,
331  bp,ret,
332  &(pMsg->m_pCipher->oKey),
333  pMsg->m_pCipher->iv,
334  &(pMsg->m_pCipher->iv_off));
335  if(myfilewrite(pMsg->m_hFileEncrypted,bp,ret)!=ret)
336  ret=E_UNKNOWN;
337  }
338  }
339  else
340  {
341  if ((pMsg->m_uLogType & MSG_LOG) == MSG_LOG)
342  {
343  #ifndef _WIN32
344  syslog(type,pMsg->m_strMsgBuff);
345  #endif
346  }
347  #ifdef COMPRESSED_LOGS
349  {
350  if(pMsg->m_gzFileInfo!=NULL)
351  {
352  if(gzwrite(pMsg->m_gzFileInfo,pMsg->m_strMsgBuff,strlen(pMsg->m_strMsgBuff))==-1)
353  ret=E_UNKNOWN;
354  }
355  }
356  #endif
357  else if ((pMsg->m_uLogType & MSG_FILE) == MSG_FILE)
358  {
359 /* if(pMsg->m_hFileInfo==-1)
360  {
361  pMsg->m_hFileInfo=open(pMsg->m_strLogFile,O_APPEND|O_CREAT|O_WRONLY|O_NONBLOCK|O_LARGEFILE|O_SYNC,S_IREAD|S_IWRITE);
362  }
363 */// if(pMsg->m_hFileInfo!=-1)
364 // {
365  #ifdef PSEUDO_LOG
366  char buff[255];
367  sprintf(buff,"%.15s mix AnonMix: ",ctime(&currtime)+4);
368  write(pMsg->m_hFileInfo,buff,strlen(buff));
369  #endif
371  ret=E_UNKNOWN;
372  pMsg->m_NrOfWrites++;
373  if( //(pMsg->m_NrOfWrites > 10000) &&
376  {
377  pMsg->closeLog();
379  }
380 // }
381  }
382  if ((pMsg->m_uLogType & MSG_STDOUT) == MSG_STDOUT)
383  {
384  printf("%s",pMsg->m_strMsgBuff);
385  }
386  }
387  pMsg->m_pcsPrint->unlock();
388  return ret;
389  }
390  else
391  {
392  printf("Warning logger is not active!\n");
393  return E_UNKNOWN;
394  }
395  }
#define LOG_ENCRYPTED
Definition: CAMsg.hpp:46
#define MSG_NOLOG
Definition: CAMsg.hpp:33
SINT64 filesize64(int handle)
Definition: CAUtil.hpp:85
bool isZero64(UINT64 &op1)
Definition: CAUtil.hpp:464
bool isGreater64(UINT64 &op1, UINT64 &op2)
Definition: CAUtil.hpp:416
SINT32 openLog(UINT32 type)
Definition: CAMsg.cpp:445
static const char *const m_strMsgTypes[6]
Definition: CAMsg.hpp:124
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41

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_NOLOG, MSG_STDOUT, myfilewrite, S_LOGENCCIPHER::oKey, openLog(), pMsg, STRMSGTYPES_SIZE, type, 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(), CAFirstMixA::accountTrafficDownstream(), CAFirstMixA::accountTrafficUpstream(), CASocketGroupEpoll::add(), CAQueue::add(), CAFirstMixChannelList::addChannel(), CACmdLnOptions::addMixIdToMixInfo(), CAThreadPool::addRequest(), TermsAndConditions::addTranslation(), CACmdLnOptions::appendMixInfo_internal(), CACryptoBenchmark::benchmarkThread(), CAAccountingControlChannel::CAAccountingControlChannel(), CAAccountingInstance::CAAccountingInstance(), CAAccountingSettleThread::CAAccountingSettleThread(), CAReplayControlChannel::CAReplayControlChannel(), CAReplayCtrlChannelMsgProc::CAReplayCtrlChannelMsgProc(), CAAccountingInstance::cascadeMatchesCC(), CAMix::checkCompatibility(), CAAccountingDBInterface::checkConnectionStatus(), checkSizesOfTypes(), CAFirstMixA::checkUserConnections(), CAFirstMix::clean(), CALastMix::clean(), CAMiddleMix::clean(), CAAccountingDBInterface::cleanup(), CALibProxytest::cleanup(), cleanup(), CAAccountingInstance::cleanupTableEntry(), CATempIPBlockList::cleanupThreadMainLoop(), CASocket::close(), CAFirstMixA::closeConnection(), CASocket::connect(), CAFirstMix::connectToNextMix(), CAMiddleMix::connectToNextMix(), CASocket::create(), CASymChannelCipherFactory::createCipher(), CACmdLnOptions::createSockets(), CACryptoBenchmark::doBenchmark(), CATLSClientSocket::doTLSConnect(), CAFirstMix::doUserLogin_internal(), CAAccountingInstance::finishLoginProcess(), CAFirstMixA::finishPacket(), CAAccountingDBInterface::getConnection(), 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(), CAAccountingDBInterface::init(), CAFirstMix::init(), CALastMix::init(), CALocalProxy::init(), CAMiddleMix::init(), CAAccountingBIInterface::initBIConnection(), CAFirstMix::initCountryStats(), CAAccountingDBInterface::initDBConnection(), CACmdLnOptions::initLogging(), CAMix::initMixCascadeInfo(), CAFirstMix::initOnce(), CALastMix::initOnce(), CALocalProxy::initOnce(), CAMiddleMix::initOnce(), CAMix::initOnce(), CAIPList::insertIP(), integrateDOMNode(), CACmdLnOptions::invokeOptionSetters(), iplist_loopDoLogCountries(), isAllowedToPassRestrictions(), CACertificate::isValid(), CAThread::join(), CASocket::listen(), logMemoryUsage(), CALocalProxy::loop(), CAMiddleMix::loop(), CAFirstMixA::loop(), CALastMixA::loop(), CAFirstMixB::loop(), CALastMixB::loop(), main(), CAAccountingSettleThread::mainLoop(), CAAccountingInstance::makeInitialCCRequest(), CADatabase::measurePerformance(), CAReplayDatabase::measurePerformance(), CADatabase::nextClock(), CAReplayDatabase::nextClock(), CAFirstMixA::notifyAllUserChannels(), CACmdLnOptions::parse(), CAHttpClient::parseHTTPHeader(), CASocket::peek(), CAFirstMixChannelList::popTimeoutEntry_internal(), CAAccountingInstance::prepareCCRequest(), CAReplayCtrlChannelMsgProc::proccessGotTimestamp(), CASyncControlChannel::proccessMessage(), CASyncControlChannel::proccessMessageComplete(), CAChain::processDownstream(), CAAccountingInstance::processJapMessage(), CALastMix::processKeyExchange(), CAMiddleMix::processKeyExchange(), CALocalProxy::processKeyExchange(), CAAccountingInstance::processThread(), CACmdLnOptions::processXmlConfiguration(), CAAccountingControlChannel::processXMLMessage(), CAReplayControlChannel::processXMLMessage(), CAReplayCtrlChannelMsgProc::propagateCurrentReplayTimestamp(), CACmdLnOptions::readXmlConfiguration(), CAMuxSocket::receive(), CASocket::receive(), CATLSClientSocket::receive(), CAFirstMix::reconfigure(), CALastMix::reconfigure(), CALastMixB::reconfigureMix(), CAAccountingDBInterface::releaseConnection(), CAThreadList::removeAll(), CALastMixChannelList::removeChannel(), CACertificate::removeColons(), CAFirstMixChannelList::removeFromTimeoutList(), CAIPList::removeIP(), CAAccountingInstance::returnKickout(), CAAccountingInstance::returnPrepareKickout(), CASocketGroup::select(), CASocket::send(), CATLSClientSocket::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(), CAFirstMixA::sendToUsers(), CACmdLnOptions::setAccountingDatabase(), CAMuxSocket::setCipher(), CAFirstMixChannelList::setDelayParameters(), CACmdLnOptions::setDynamicMix(), CASocket::setKeepAlive(), CASymCipherOFB::setKeys(), 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(), CAXMLErrorMessage::setValues(), CASignature::setVerifyKey(), CAThreadList::showAll(), CAFirstMixA::shutDown(), signal_interrupt(), signal_segv(), signal_term(), CAMultiSignature::signXML(), SIGUSR1_handler(), SIGUSR2_handler(), CAInfoService::start(), CALocalProxy::start(), CAMix::start(), CAThread::start(), CAAccountingBIInterface::terminateBIConnection(), CAFirstMix::updateCountryStats(), CACertificate::verify(), CACertStore::verifyMixCert(), CAMultiSignature::verifyXML(), CAThreadList::waitAndRemoveAll(), CAAccountingControlChannel::~CAAccountingControlChannel(), CAAccountingInstance::~CAAccountingInstance(), CAChain::~CAChain(), CAReplayCtrlChannelMsgProc::~CAReplayCtrlChannelMsgProc(), and CATempIPBlockList::~CATempIPBlockList().

Here is the call graph for this function:

◆ rotateLog()

SINT32 CAMsg::rotateLog ( )
private

Definition at line 422 of file CAMsg.cpp.

423 {
425  {
426  // TODO
427  }
428  else if ((pMsg->m_uLogType & MSG_FILE) == MSG_FILE)
429  {
430 
431  char logFileSaveName[1026];
432  memset(logFileSaveName, 0, 1026);
433  //memcpy(logFileSave, m_strMsgBuff, 1024);
434  snprintf(logFileSaveName, 1025, "%s%u", m_strLogFile, m_lastLogFileNumber);
436  rename(m_strLogFile, logFileSaveName);
437  /*if(m_hFileInfo!=-1)
438  close(m_hFileInfo);
439  m_hFileInfo=-1;*/
440  }
441 
442  return E_SUCCESS;
443 }
UINT32 getMaxLogFiles()

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

Referenced by openLog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setLogLevel()

SINT32 CAMsg::setLogLevel ( UINT32  a_logLevel)
static

Definition at line 127 of file CAMsg.cpp.

128 {
129  if (a_logLevel == LOG_DEBUG ||
130  a_logLevel == LOG_INFO ||
131  a_logLevel == LOG_WARNING ||
132  a_logLevel == LOG_ERR ||
133  a_logLevel == LOG_CRIT)
134  {
135  pMsg->m_logLevel = a_logLevel;
136  return E_SUCCESS;
137  }
138  return E_UNKNOWN;
139 }

References E_SUCCESS, E_UNKNOWN, m_logLevel, and pMsg.

Referenced by CACmdLnOptions::initLogging().

Here is the caller graph for this function:

◆ setLogOptions()

SINT32 CAMsg::setLogOptions ( UINT32  options)
static

Definition at line 161 of file CAMsg.cpp.

162  {
163  SINT32 ret;
164  const char* strLogOpened = "Message log opened%s%s.\n";
165  const char* strLogErrorMsg = "Could not open message log%s%s!%s Do you have write permissions?%s\n";
166  const char* strReasonMsg = " Reason: %s (%u)";
167  char* strLogFile = NULL;
168  char* strLogDir = NULL;
169  char* strReason = NULL;
170  char* strBuff;
171  const char* strLogType = "";
172 
173 
174  if(pMsg->m_uLogType==opt)
175  {
176  return E_SUCCESS;
177  }
178 
179 
180  if (opt == MSG_LOG)
181  {
182  strLogType = " as Syslog";
183  }
184  else if ((opt & MSG_LOG) == MSG_LOG)
185  {
186  strLogType = " as Syslog and";
187  }
188 
189  if ((opt & MSG_FILE) == MSG_FILE)
190  {
191  strLogType = " as file";
192  }
193  else if ((opt & MSG_COMPRESSED_FILE) == MSG_COMPRESSED_FILE)
194  {
195  strLogType = " as compressed file";
196  }
197 
198 
199 
200  if((ret = pMsg->openLog(opt))==E_SUCCESS)
201  {
202  strLogFile = pMsg->createLogFileMessage(opt);
203  strBuff = new char[strlen(strLogOpened) + strlen(strLogType) + strlen(strLogFile) + 1];
204  sprintf(strBuff, strLogOpened, strLogType, strLogFile);
205  delete[] strLogFile;
206  printMsg(LOG_DEBUG, strBuff);
207  delete[] strBuff;
208 
209  pMsg->closeLog(); //closes the OLD Log!
210  pMsg->m_uLogType=opt;
211 
212 
213  return E_SUCCESS;
214  }
215 
216 
217  strLogFile = pMsg->createLogFileMessage(opt);
218 
219  strLogDir = pMsg->createLogDirMessage(opt);
220 
221  if (ret == E_FILE_OPEN)
222  {
223  strReason = new char[strlen(strReasonMsg) + strlen(GET_NET_ERROR_STR(GET_NET_ERROR)) + 5 + 1];
224  sprintf(strReason, strReasonMsg, GET_NET_ERROR_STR(GET_NET_ERROR), GET_NET_ERROR);
225  }
226  else
227  {
228  strReason = new char[1];
229  strReason[0] = '\0';
230  }
231 
232  strBuff = new char[strlen(strLogErrorMsg) + strlen(strLogType) + strlen(strLogFile) + strlen(strReason) + strlen(strLogDir) + 1];
233 
234  sprintf(strBuff, strLogErrorMsg, strLogType, strLogFile, strReason, strLogDir);
235  //snprintf(strBuff, strlen(strLogErrorMsg) + strlen(strLogFile) + strlen(strReason) + 1, strLogErrorMsg, strLogFile, strReason);
236  delete[] strLogFile;
237  delete[] strReason;
238 
239  printMsg(LOG_CRIT, strBuff);
240 
241  delete[] strBuff;
242  return ret;
243  }
#define GET_NET_ERROR_STR(x)
Definition: StdAfx.h:471
char * createLogDirMessage(UINT32 opt)
Definition: CAMsg.cpp:104
char * createLogFileMessage(UINT32 opt)
Definition: CAMsg.cpp:82
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMaxLogFileSize()

static SINT32 CAMsg::setMaxLogFileSize ( UINT64  size)
inlinestatic

Definition at line 90 of file CAMsg.hpp.

91  {
92  if(pMsg!=NULL)
93  {
95  return E_SUCCESS;
96  }
97  return E_UNKNOWN;
98  }
void set64(UINT64 &op1, UINT32 op2)
Definition: CAUtil.hpp:321

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

Referenced by openLog().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_alreadyOpened

bool CAMsg::m_alreadyOpened
private

Definition at line 118 of file CAMsg.hpp.

Referenced by CAMsg(), and openLog().

◆ m_hFileEncrypted

int CAMsg::m_hFileEncrypted
private

Definition at line 119 of file CAMsg.hpp.

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

◆ m_hFileInfo

int CAMsg::m_hFileInfo
private

Definition at line 120 of file CAMsg.hpp.

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

◆ m_lastLogFileNumber

UINT32 CAMsg::m_lastLogFileNumber
private

Definition at line 117 of file CAMsg.hpp.

Referenced by CAMsg(), and rotateLog().

◆ m_logLevel

UINT32 CAMsg::m_logLevel
private

Definition at line 116 of file CAMsg.hpp.

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

◆ m_maxLogFileSize

SINT64 CAMsg::m_maxLogFileSize
private

Definition at line 108 of file CAMsg.hpp.

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

◆ m_NrOfWrites

UINT32 CAMsg::m_NrOfWrites
private

Definition at line 109 of file CAMsg.hpp.

Referenced by openLog(), and printMsg().

◆ m_pCipher

t_LogEncCipher* CAMsg::m_pCipher
private

Definition at line 129 of file CAMsg.hpp.

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

◆ m_pcsPrint

CAMutex* CAMsg::m_pcsPrint
private

Definition at line 125 of file CAMsg.hpp.

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

◆ m_strLogDir

char* CAMsg::m_strLogDir
private

Definition at line 123 of file CAMsg.hpp.

Referenced by createLogDirMessage(), and openLog().

◆ m_strLogFile

char* CAMsg::m_strLogFile
private

Definition at line 122 of file CAMsg.hpp.

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

◆ m_strMsgBuff

char* CAMsg::m_strMsgBuff
private

Definition at line 121 of file CAMsg.hpp.

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

◆ m_strMsgTypes

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

Definition at line 124 of file CAMsg.hpp.

Referenced by printMsg().

◆ m_uLogType

UINT32 CAMsg::m_uLogType
private

Definition at line 115 of file CAMsg.hpp.

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

◆ ms_arStrLogLevels

const char *const CAMsg::ms_arStrLogLevels = { "CRITICAL","ERROR","WARNING","INFO","DEBUG" }
staticprivate

Definition at line 66 of file CAMsg.hpp.

Referenced by getLogLevelStr().

◆ pMsg

CAMsg * CAMsg::pMsg =NULL
staticprivate

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