2
* log.cpp - log files handling functions
3
* $Id: log.cpp,v 1.3 2004/06/05 15:15:17 rdenisc Exp $
6
/***********************************************************************
7
* Copyright (C) 2002-2004 Remi Denis-Courmont. *
8
* This program is free software; you can redistribute and/or modify *
9
* it under the terms of the GNU General Public License as published *
10
* by the Free Software Foundation; version 2 of the license. *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
15
* See the GNU General Public License for more details. *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program; if not, you can get it from: *
19
* http://www.gnu.org/copyleft/gpl.html *
20
***********************************************************************/
32
/*** DataLog class implementation ***/
33
DataLog::~DataLog (void)
35
if ((out != NULL) && close_out)
41
DataLog::Connect (const char *, const char *,
42
const char *, const char *)
48
DataLog::WriteServerData (const void *, int length, int)
55
DataLog::WriteClientData (const void *, int length, int)
62
DataLog::ShutdownServer (void)
68
DataLog::ShutdownClient (void)
73
/*** DataLogList implementation ***/
75
DataLogList::AddLog (DataLog *log)
80
struct listnode *node;
98
DataLogList::~DataLogList (void)
100
for (struct listnode *node = head; node != NULL; node = head)
110
DataLogList::WriteServerData (const void *data, int length, int oob)
112
for (struct listnode *node = head; node != NULL; node = node->next)
113
if (node->log->WriteServerData (data, length, oob) != length)
121
DataLogList::WriteClientData (const void *data, int length, int oob)
123
for (struct listnode *node = head; node != NULL; node = node->next)
124
if (node->log->WriteClientData (data, length, oob) != length)
132
DataLogList::ShutdownServer (void)
134
for (struct listnode *node = head; node != NULL; node = node->next)
135
node->log->ShutdownServer ();
140
DataLogList::ShutdownClient (void)
142
for (struct listnode *node = head; node != NULL; node = node->next)
143
node->log->ShutdownClient ();
148
DataLogList::Connect (const char *server, const char *service,
149
const char *client, const char *port)
151
for (struct listnode *node = head; node != NULL; node = node->next)
152
node->log->Connect (server, service, client, port);
156
/*** DataLogListMaker implementation ***/
158
DataLogListMaker::AddLogMaker (DataLog *(*maker) (void), FILE *stream)
160
struct listnode *node;
164
node = new struct listnode;
173
node->basename = NULL;
174
node->stream = stream;
181
DataLogListMaker::AddLogMaker (DataLog *(*maker) (void), const char *prefix)
183
struct listnode *node;
187
node = new struct listnode;
197
node->basename = strdup (prefix);
198
if (node->basename == NULL)
210
DataLogListMaker::~DataLogListMaker (void)
212
for (struct listnode *node = head; node != NULL; node = head)
215
if (node->basename != NULL)
216
delete node->basename;
223
DataLogListMaker::MakeLogList (const char *addr, const char *port) const
229
list = new DataLogList;
236
// Creates a log for each maker in the list
237
for (struct listnode *node = head; node != NULL; node = node->next)
243
log = node->maker ();
253
// Adds a log in the list
254
if (list->AddLog (log))
261
// Attaches a stream to the new log
262
if (node->stream != NULL)
263
log->SetStream (node->stream, 0);
265
{ // Do we need more abstraction?
266
const char *prefix = node->basename;
276
int len = strlen (prefix) + strlen (addr)
281
filename = new char[len];
288
snprintf (filename, len, "%s-%s-%s",
291
FILE *stream = secure_fopen (filename, "a");
299
log->SetStream (stream);