/***************************************************************************** POPular -- A POP3 server and proxy for large mail systems $Id: xlog.c,v 1.21 2001/05/17 20:17:23 sqrt Exp $ http://www.remote.org/jochen/mail/popular/ ****************************************************************************** Copyright (C) 1999-2001 Jochen Topf This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA *****************************************************************************/ #if HAVE_CONFIG_H # include #endif #include "popular.h" static char xhostname[256]; static char xprgname[256]; static char xid[256]; /* in the beginning the file descriptor for logging is 2 for stdout */ static int xfd = 2; /***************************************************************************** xlog_writeln() Internal function This function is used by the logging function, it writes a line to the logfile. Tabs, newlines and carriage returns are printed as space, non- printable characters are printed as a dot (.). A single newline is included at the end. *****************************************************************************/ void xlog_writeln(char *string) { char buf[strlen(string)*4+2]; unsigned char *s, *t; /* no logging if there is no fd to log to */ if (xfd == -1) return; for (s=string, t=buf; *s; s++, t++) { if (*s == '\n') { *t++ = '\\'; *t = 'n'; } else if (*s == '\r') { *t++ = '\\'; *t = 'r'; } else if (*s == '\t') { *t++ = '\\'; *t = 't'; } else if (*s == '\"') { *t++ = '\\'; *t = '\"'; } else if (*s == '\\') { *t++ = '\\'; *t = '\\'; } else if (isprint(*s)) { *t = *s; } else { *t++ = '\\'; *t++ = 'x'; snprintf(t++, 3, "%02x", (unsigned int) *s); } } *t++ = '\n'; *t = '\0'; (void) rel_write(xfd, buf, strlen(buf)); } /***************************************************************************** xlog_print_level() *****************************************************************************/ const char * xlog_print_level(xlog_level_t level) { switch (level) { case xlog_dbg: return("DBG"); case xlog_inf: return("INF"); case xlog_err: return("ERR"); case xlog_adm: return("ADM"); case xlog_sos: return("SOS"); case xlog_bug: return("BUG"); } return("BUG"); } /***************************************************************************** xlog_printf() Write some information to the logfile and exit. Long strings will be truncated. ('...' is printed at the end to signal truncation.) The following characters are printed like escpaed: \r, \n, \t, \\, \". Other nonprintable characters are printedas hexadecimal: \xXX. Log format: