2
* log.cc - log files handling functions
3
* $Id: log.cc,v 1.9 2003/01/26 09:09:08 rdenisc Exp $
6
/***********************************************************************
7
* Copyright (C) 2002-2003 R�mi 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 Pulic License *
18
* along with this program; if not, you can get it from: *
19
* http://www.gnu.org/copyleft/gpl.html *
20
***********************************************************************/
33
/*** DataLog class implementation ***/
34
DataLog::~DataLog (void)
36
if ((out != NULL) && close_out)
42
DataLog::Connect (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
/* FIXME: errors not handled */
114
node->log->WriteServerData (data, length, oob);
119
DataLogList::WriteClientData (const void *data, int length, int oob)
121
for (struct listnode *node = head; node != NULL; node = node->next)
122
/* FIXME: errors not handled */
123
node->log->WriteClientData (data, length, oob);
128
DataLogList::ShutdownServer (void)
130
for (struct listnode *node = head; node != NULL; node = node->next)
131
node->log->ShutdownServer ();
136
DataLogList::ShutdownClient (void)
138
for (struct listnode *node = head; node != NULL; node = node->next)
139
node->log->ShutdownClient ();
144
DataLogList::Connect (const char *server, const char *client)
146
for (struct listnode *node = head; node != NULL; node = node->next)
147
node->log->Connect (server, client);
151
/*** DataLogListMaker implementation ***/
153
DataLogListMaker::AddLogMaker (DataLog *(*maker) (void), FILE *stream)
155
struct listnode *node;
159
node = new struct listnode;
168
node->basename = NULL;
169
node->stream = stream;
176
DataLogListMaker::AddLogMaker (DataLog *(*maker) (void), const char *prefix)
178
struct listnode *node;
182
node = new struct listnode;
192
/* FIXME: could be improved */
195
int len = strlen (prefix) + 1;
206
memcpy (buf, prefix, len);
208
node->basename = buf;
217
DataLogListMaker::~DataLogListMaker (void)
219
for (struct listnode *node = head; node != NULL; node = head)
222
if (node->basename != NULL)
223
delete node->basename;
230
char *valid_chars (char *str)
234
for (char *ptr = str; (c = *ptr) != 0; ptr++)
247
DataLogListMaker::MakeLogList (const char *suffix)
253
list = new DataLogList;
260
// Creates a log for each maker in the list
261
for (struct listnode *node = head; node != NULL; node = node->next)
267
log = node->maker ();
277
// Adds a log in the list
278
if (list->AddLog (log))
285
// Attaches a stream to the new log
286
if (node->stream != NULL)
287
log->SetStream (node->stream, 0);
289
{ // Do we need more abstraction?
290
const char *prefix = node->basename;
298
int len = strlen (prefix) + strlen (suffix)+1;
302
filename = new char[len];
309
sprintf (filename, "%s%s", prefix, suffix);
310
valid_chars (filename);
312
FILE *stream = secure_append_fopen (filename);
320
log->SetStream (stream);