File: licq_log.h

package info (click to toggle)
licq 1.3.4-2etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 22,052 kB
  • ctags: 8,640
  • sloc: cpp: 76,924; sh: 9,845; ansic: 5,424; perl: 3,449; lex: 857; xml: 804; php: 691; makefile: 393; csh: 48
file content (233 lines) | stat: -rw-r--r-- 6,593 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#ifndef LOG_H
#define LOG_H

#include <stdarg.h>
#include <vector>
#include <stdio.h>
#include <list>
#include <pthread.h>

#include "licq_constants.h"

// Info: basic information about what's going on
const unsigned short L_INFO     = 0x0001;
// Unknown: unknown packets or bytes
const unsigned short L_UNKNOWN  = 0x0002;
// Error: critical errors which should be brought to the attention of the user
const unsigned short L_ERROR    = 0x0004;
// Warn: warnings which are not critical but could be important
const unsigned short L_WARN     = 0x0008;
// Packet: packet dumps
const unsigned short L_PACKET   = 0x0010;
// Message: popup messages from plugins to be displayed to the user
const unsigned short L_MESSAGE  = 0x8000;

const unsigned short L_MOST     = L_INFO | L_UNKNOWN | L_ERROR | L_WARN | L_MESSAGE;
const unsigned short L_ALL      = L_MOST | L_PACKET;
const unsigned short L_NONE     = 0;

const char L_WARNxSTR[]    = "[WRN] ";
const char L_TCPxSTR[]     = "[TCP] ";
const char L_SRVxSTR[]     = "[SRV] ";
const char L_ERRORxSTR[]   = "[ERR] ";
const char L_UNKNOWNxSTR[] = "[???] ";
const char L_BLANKxSTR[]   = "                ";
const char L_SBLANKxSTR[]  = "      ";
const char L_PACKETxSTR[]  = "[PKT] ";
const char L_INITxSTR[]    = "[INI] ";
const char L_ENDxSTR[]     = "[END] ";
const char L_FIFOxSTR[]    = "[FIF] ";
const char L_SSLxSTR[]     = "[SSL] ";

const unsigned short S_STDERR   = 1;
const unsigned short S_FILE     = 2;
const unsigned short S_PLUGIN   = 4;
const unsigned short S_ALL	= S_STDERR | S_FILE | S_PLUGIN;

const unsigned short LOG_PREFIX_OFFSET = 10;

const unsigned short MAX_MSG_SIZE = 2048;


//-----CLogService---------------------------------------------------------------
class CLogService
{
public:
  CLogService(unsigned short _nLogTypes);
  virtual ~CLogService() { }

  virtual void LogMessage(const char *_szPrefix, const char *_szMessage, 
			  unsigned short _nLogType) = 0;
  void SetLogTypes(unsigned short _nLogTypes);
  unsigned short ServiceType();
  unsigned short LogType(unsigned short _nLogType);
  void AddLogType(unsigned short _nLogType);
  void RemoveLogType(unsigned short _nLogType);
  void SetData(void *);

  static int LoggingPackets()  {  return s_nLoggingPackets; }

protected:
  unsigned short m_nLogTypes;
  unsigned short m_nServiceType;
  void *m_pData;

  static int s_nLoggingPackets;
};


//-----StdErr-------------------------------------------------------------------
class CLogService_StdErr : public CLogService
{
public:
  CLogService_StdErr(unsigned short _nLogTypes, bool _bUseColor);
  virtual void LogMessage(const char *_szPrefix, const char *_szMessage, 
			  unsigned short _nLogType);
protected:
  bool m_bUseColor;
};


//-----File---------------------------------------------------------------------
class CLogService_File : public CLogService
{
public:
   CLogService_File(unsigned short _nLogTypes);
   ~CLogService_File();

   bool SetLogFile(const char *_szFile, const char *_szFlags);
   virtual void LogMessage(const char *_szPrefix, const char *_szMessage, 
			   unsigned short _nLogType);
protected:
   FILE *m_fLog;
};


//-----Plugin------------------------------------------------------------------
class CPluginLog
{
public:
  CPluginLog();
  char *NextLogMsg();
  unsigned short NextLogType();
  void ClearLog();
  void AddLog(char *_szLog, unsigned short _nLogType);
  int Pipe()  { return pipe_log[PIPE_READ]; }
protected:
  pthread_mutex_t mutex;
  std::list <char *> m_vszLogs;
  std::list <unsigned short> m_vnLogTypes;
  int pipe_log[2];
};

class CLogService_Plugin : public CLogService
{
public:
  CLogService_Plugin(CPluginLog *_xWindow, unsigned short _nLogTypes);
  bool SetLogWindow(CPluginLog *_xWindow);
  CPluginLog *LogWindow() { return m_xLogWindow; }
  virtual void LogMessage(const char *_szPrefix, const char *_szMessage, 
			  const unsigned short _nLogType);
protected:
  CPluginLog *m_xLogWindow;
};


//-----CLogServer---------------------------------------------------------------
class CLogServer
{
public:
  CLogServer();
  ~CLogServer();

  void AddService(CLogService *_xService);
  void AddLogTypeToService(unsigned short _nServiceType, unsigned short _nLogType);
  void RemoveLogTypeFromService(unsigned short _nServiceType, unsigned short _nLogType);
  void ModifyService(unsigned short _nServiceType, unsigned short _nLogTypes);
  unsigned short ServiceLogTypes(unsigned short _nServiceType);
  void SetServiceData(unsigned short _nServiceType, void *_pData);

  bool LoggingPackets()  {  return CLogService::LoggingPackets() > 0;  }

  void Info(const char *, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 2, 3)))
#endif
;
  void Info(unsigned short _nServiceTypes, const char *_szFormat, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 3, 4)))
#endif
;
  void Unknown(const char *, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 2, 3)))
#endif
;
  void Unknown(unsigned short _nServiceTypes, const char *_szFormat, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 3, 4)))
#endif
;
  void Error(const char *_szFormat, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 2, 3)))
#endif
;
  void Error(unsigned short _nServiceTypes, const char *_szFormat, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 3, 4)))
#endif
;
  void Warn(const char *_szFormat, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 2, 3)))
#endif
;
  void Warn(unsigned short _nServiceTypes, const char *_szFormat, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 3, 4)))
#endif
;
  void Packet(const char *_szFormat, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 2, 3)))
#endif
;
  void Packet(unsigned short _nServiceTypes, const char *_szFormat, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 3, 4)))
#endif
;
  void Message(const char *_szFormat, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 2, 3)))
#endif
;
  void Message(unsigned short _nServiceTypes, const char *_szFormat, ...)
#ifdef __GNUC__
    __attribute__ ((format (printf, 3, 4)))
#endif
;

protected:
  std::vector <CLogService *> m_vxLogServices;
  pthread_mutex_t mutex;
  void Log(const unsigned short _nLogType, const char *_szFormat, va_list argp)
#ifdef __GNUC__
    __attribute__ ((format (printf, 3, 0)))
#endif
;
  void Log(const unsigned short _nServiceTypes, const unsigned short _nLogType, const char *_szFormat, va_list argp)
#ifdef __GNUC__
    __attribute__ ((format (printf, 4, 0)))
#endif
;
};


// Define an external log server to be started in log.cpp
extern CLogServer gLog;


#endif