Mixe for Privacy and Anonymity in the Internet
CAMsg.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 // TODO: Sylog for NT!!
29 
30 #ifndef __CAMSG__
31 #define __CAMSG__
32 
33 #define MSG_NOLOG 0x00
34 #define MSG_STDOUT 0x01
35 #define MSG_LOG 0x02
36 #define MSG_FILE 0x04
37 #define MSG_COMPRESSED_FILE 0x08
38 
39 #ifdef _WIN32
40  #define LOG_ERR 0
41  #define LOG_CRIT 1
42  #define LOG_INFO 2
43  #define LOG_DEBUG 3
44  #define LOG_WARNING 4
45 #endif
46 #define LOG_ENCRYPTED 255
47 
48 #include "CAMutex.hpp"
49 #include "CASymCipher.hpp"
50 #include "CAUtil.hpp"
51 
53 {
54  UINT8 iv[16];
55  int iv_off;
56  AES_KEY oKey;
57 };
58 
60 
61 class CAMsg
62  {
63  private:
64  CAMsg(); //Singleton!
65  static CAMsg* pMsg;
66  static const char* const ms_arStrLogLevels[5];
67  public:
68  ~CAMsg();
69  static SINT32 init()
70  {
71  if (pMsg == NULL)
72  {
73  pMsg=new CAMsg();
74  }
75  return E_SUCCESS;
76  }
77  static SINT32 cleanup()
78  {
79  if (pMsg != NULL)
80  {
81  pMsg->closeLog();
82  }
83  delete pMsg;
84  pMsg = NULL;
85  return E_SUCCESS;
86  }
87  static SINT32 setLogOptions(UINT32 options);
88  static SINT32 setLogLevel(UINT32 a_logLevel);
89  static const char* const getLogLevelStr();
91  {
92  if(pMsg!=NULL)
93  {
95  return E_SUCCESS;
96  }
97  return E_UNKNOWN;
98  }
99 
100  static SINT32 printMsg(UINT32 typ,const char* format,...);
101  //static SINT32 printBytes(UINT32 typ,const char* msg,const UINT8* bytes,UINT32 bytesLen);
102 
103 #ifndef ONLY_LOCAL_PROXY
104  static SINT32 openEncryptedLog();
105  static SINT32 closeEncryptedLog();
106 #endif //ONLY_LOCAL_PROXY
107  private:
111  SINT32 closeLog();
112  SINT32 rotateLog();
113  char* createLogFileMessage(UINT32 opt);
114  char* createLogDirMessage(UINT32 opt);
123  char *m_strLogDir;
124  static const char* const m_strMsgTypes[6];
126 #ifdef COMPRESSED_LOGS
127  gzFile m_gzFileInfo;
128 #endif
130  };
131 #endif
S_LOGENCCIPHER t_LogEncCipher
Definition: CAMsg.hpp:59
void set64(UINT64 &op1, UINT32 op2)
Definition: CAUtil.hpp:321
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
Definition: CAMsg.hpp:62
static SINT32 init()
Definition: CAMsg.hpp:69
static CAMsg * pMsg
Definition: CAMsg.hpp:65
char * m_strLogFile
Definition: CAMsg.hpp:122
static SINT32 openEncryptedLog()
Open a log, where the logged messages are store encrypted.
Definition: CAMsg.cpp:520
static const char *const getLogLevelStr()
Definition: CAMsg.cpp:143
SINT32 openLog(UINT32 type)
Definition: CAMsg.cpp:445
char * createLogDirMessage(UINT32 opt)
Definition: CAMsg.cpp:104
UINT32 m_NrOfWrites
Definition: CAMsg.hpp:109
static SINT32 setMaxLogFileSize(UINT64 size)
Definition: CAMsg.hpp:90
bool m_alreadyOpened
Definition: CAMsg.hpp:118
static SINT32 setLogOptions(UINT32 options)
Definition: CAMsg.cpp:161
char * m_strLogDir
Definition: CAMsg.hpp:123
CAMsg()
Definition: CAMsg.cpp:49
SINT64 m_maxLogFileSize
Definition: CAMsg.hpp:108
SINT32 rotateLog()
Definition: CAMsg.cpp:422
static SINT32 cleanup()
Definition: CAMsg.hpp:77
t_LogEncCipher * m_pCipher
Definition: CAMsg.hpp:129
static SINT32 setLogLevel(UINT32 a_logLevel)
Definition: CAMsg.cpp:127
~CAMsg()
Definition: CAMsg.cpp:68
UINT32 m_lastLogFileNumber
Definition: CAMsg.hpp:117
char * createLogFileMessage(UINT32 opt)
Definition: CAMsg.cpp:82
int m_hFileEncrypted
Definition: CAMsg.hpp:119
SINT32 closeLog()
Definition: CAMsg.cpp:397
char * m_strMsgBuff
Definition: CAMsg.hpp:121
static const char *const m_strMsgTypes[6]
Definition: CAMsg.hpp:124
static const char *const ms_arStrLogLevels[5]
Definition: CAMsg.hpp:66
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
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
static SINT32 closeEncryptedLog()
Definition: CAMsg.cpp:560
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
#define E_UNKNOWN
Definition: errorcodes.hpp:3
AES_KEY oKey
Definition: CAMsg.hpp:56
UINT8 iv[16]
Definition: CAMsg.hpp:54
UINT8 type
Definition: typedefs.hpp:1