~ubuntu-branches/ubuntu/natty/ntop/natty

« back to all changes in this revision

Viewing changes to ntop/logger.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2005-01-30 21:59:13 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050130215913-xc3ke963bw49b3k4
Tags: 2:3.0-5
* Updated README.Debian file so users will understand what to do at
  install, closes: #291794, #287802.
* Updated ntop init script to give better output.
* Also changed log directory from /var/lib/ntop to /var/log/ntop,
  closes: #252352.
* Quoted the interface list to allow whitespace, closes: #267248.
* Added a couple of logcheck ignores, closes: #269321, #269319.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (C) 1998-2001 Luca Deri <deri@ntop.org>
3
 
 *                          Portions by Stefano Suin <stefano@ntop.org>
4
 
 *                      
5
 
 *                          http://www.ntop.org/
6
 
 *                                      
7
 
 *  This program is free software; you can redistribute it and/or modify
8
 
 *  it under the terms of the GNU General Public License as published by
9
 
 *  the Free Software Foundation; either version 2 of the License, or
10
 
 *  (at your option) any later version.
11
 
 *
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.  See the
15
 
 *  GNU General Public License for more details.
16
 
 *
17
 
 *  You should have received a copy of the GNU General Public License
18
 
 *  along with this program; if not, write to the Free Software
19
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
 
 */
21
 
 
22
 
 
23
 
#include "ntop.h"
24
 
 
25
 
#ifdef HAVE_GDBM_H
26
 
static GDBM_FILE logDB;
27
 
#endif
28
 
 
29
 
/* *************************** */
30
 
 
31
 
void initLogger(void) {
32
 
#ifdef HAVE_GDBM_H
33
 
  char tmpBuff[200];
34
 
  if(snprintf(tmpBuff, sizeof(tmpBuff), "%s/logger.db",dbPath) < 0) 
35
 
    traceEvent(TRACE_ERROR, "Buffer overflow!");
36
 
  logDB = gdbm_open (tmpBuff, 0, GDBM_NEWDB, 00664, NULL);
37
 
#endif
38
 
}
39
 
 
40
 
/* *************************** */
41
 
 
42
 
void termLogger(void) {
43
 
#ifdef HAVE_GDBM_H
44
 
  if(logDB != NULL) {
45
 
#ifdef MULTITHREADED
46
 
    accessMutex(&gdbmMutex, "termLogger");
47
 
#endif 
48
 
    gdbm_close(logDB);
49
 
#ifdef MULTITHREADED
50
 
  releaseMutex(&gdbmMutex);
51
 
#endif
52
 
    logDB = NULL;
53
 
  }
54
 
#endif
55
 
}
56
 
 
57
 
/* *************************** */
58
 
#ifdef HAVE_GDBM_H
59
 
void logMessage(char* message, u_short severity) {
60
 
  LogMessage msg;
61
 
  int len;
62
 
  datum key_data, data_data;
63
 
  char tmpStr[16];
64
 
 
65
 
  if((message == NULL) || (logDB == NULL))
66
 
    return;
67
 
 
68
 
  memset(&msg, 0, sizeof(LogMessage));
69
 
  msg.severity = severity;
70
 
  len = strlen(message);
71
 
 
72
 
  if(len > MESSAGE_MAX_LEN) len = MESSAGE_MAX_LEN;
73
 
  strncpy(msg.message, message, len);
74
 
  msg.message[len]= '\0';
75
 
 
76
 
  if(snprintf(tmpStr, sizeof(tmpStr), "%lu", time(NULL)) < 0)
77
 
    traceEvent(TRACE_ERROR, "Buffer overflow!");
78
 
  key_data.dptr = tmpStr; key_data.dsize = strlen(key_data.dptr)+1;
79
 
  data_data.dptr = (char*)&msg; data_data.dsize = sizeof(LogMessage)+1;
80
 
  
81
 
#ifdef MULTITHREADED
82
 
  accessMutex(&gdbmMutex, "logMessage");
83
 
#endif 
84
 
  gdbm_store(logDB, key_data, data_data, GDBM_REPLACE); 
85
 
#ifdef MULTITHREADED
86
 
  releaseMutex(&gdbmMutex);
87
 
#endif 
88
 
}
89
 
#else
90
 
void logMessage(char* message, u_short severity) {
91
 
  traceEvent(TRACE_INFO,"%s [severity %d]\n", message, severity);
92
 
}
93
 
#endif
94