1 // Copyright (C) 1999,2000 Bruce Guenter <bruceg@em.ca>
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16 
17 #include <config.h>
18 #include "daemon.h"
19 
20 mystring logstr;
21 
22 extern bool opt_log_all;
23 static pid_t pid = 0;
24 
25 const mystring LOG_PASSWORD = "<password>";
26 const mystring LOG_NEWPASS = "<newpass>";
27 const mystring LOG_ADMINPASS = "<adminpass>";
28 const mystring LOG_MESSAGE = "<message>";
29 
30 static const char* request_str = "Request: ";
31 
log()32 fdobuf& log()
33 {
34   if(!pid)
35     pid = getpid();
36   ferr << '[' << pid << "] ";
37   return ferr;
38 }
39 
log(const char * msg)40 void log(const char* msg)
41 {
42   log() << msg << endl;
43 }
44 
finish(const mystring & str)45 static void finish(const mystring& str)
46 {
47   if(opt_log_all)
48     log() << request_str << str << endl;
49   else
50     logstr = str;
51 }
52 
logcommand(const command & cmd)53 void logcommand(const command& cmd)
54 {
55   mystring out = cmd.name();
56   for(unsigned i = 0; i < cmd.count(); i++)
57     out = out + " " + cmd[i];
58   finish(out);
59 }
60 
logresponse(const response & res)61 void logresponse(const response& res)
62 {
63   if(opt_log_all || !res) {
64     if(!logstr.empty()) {
65       log() << request_str << logstr << endl;
66       logstr = "";
67     }
68     log() << "Completed: " << res.message() << endl;
69   }
70 }
71