Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

log.h

Go to the documentation of this file.
00001 #ifndef __log_h__
00002 #define __log_h__
00003 
00012 /*
00013  * Copyright (c) 2001 James Hess
00014  * All rights reserved.
00015  *
00016  * Redistribution and use in source and binary forms, with or without
00017  * modification, are permitted provided that the following conditions
00018  * are met:
00019  * 1. Redistributions of source code must retain the above copyright
00020  *    notice, this list of conditions and the following disclaimer.
00021  * 2. Redistributions in binary form must reproduce the above copyright
00022  *    notice, this list of conditions and the following disclaimer in the
00023  *    documentation and/or other materials provided with the distribution.
00024  * 3. Neither the name of the authors nor the names of its contributors
00025  *    may be used to endorse or promote products derived from this software
00026  *    without specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
00029  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
00032  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00034  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00035  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00036  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00037  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00038  * SUCH DAMAGE.
00039  */
00040 
00041 #include "interp.h"
00042 
00043 extern const char *fullhost1(const UserList *);
00044 
00048 extern const char *nullFmtHack;
00049 
00050 /* Log flags */
00052 #define LOGF_NORMAL 0x0
00053 
00055 #define LOGF_BADPW  0x1
00056 
00058 #define LOGF_FAIL   0x2
00059 
00061 #define LOGF_OFF    0x4
00062 
00064 #define LOGF_ON     0x8
00065 
00067 #define LOGF_OPER   0x10
00068 
00070 #define LOGF_PATTERN    0x20
00071 
00073 #define LOGF_SCAN   0x40
00074 
00076 #define LOGF_OK     0x80
00077 
00081 class SLogfile {
00082   public:
00083     SLogfile(const char *fname) : fp(NULL), fpw(NULL), logFileName(0),
00084                                   logwFileName(0), fp_noclose(0), fpw_noclose(0)
00085    {
00086       /*if (!(db = dbopen(fname, O_RDWR | O_EXLOCK | O_CREAT, DB_HASH, NULL))) {
00087           fprintf(stderr, "Error: Could not open %s: %s\n", fname ? fname :
00088                   "", strerror(errno)); 
00089           sshutdown(0);
00090       }*/
00091       if (!(fp = fopen(fname, "a"))) {
00092           fprintf(stderr, "Error: Could not open %s: %s\n", fname ? fname :
00093                   "", strerror(errno)); 
00094           sshutdown(0);
00095       }
00096 
00097       logFileName = static_cast<char *>(oalloc(strlen(fname) + 1));
00098       strcpy(logFileName, fname);
00099     }
00100 
00101     SLogfile(const SLogfile& x) {
00102          if (x.logFileName) {
00103              logFileName = static_cast<char *>(oalloc(strlen(x.logFileName) + 1));
00104              strcpy(logFileName, x.logFileName);
00105          }
00106          if (x.logwFileName) {
00107              logwFileName = static_cast<char *>(oalloc(strlen(x.logwFileName) + 1));
00108              strcpy(logwFileName, x.logFileName);
00109          }
00110          if (x.fp)
00111              fp_noclose = 1;
00112          if (x.fpw)
00113              fpw_noclose = 1;
00114     }
00115 
00116     SLogfile(const char *fname, const char *fnamew) : fp(NULL), fpw(NULL),
00117       logFileName(0), logwFileName(0), fp_noclose(0), fpw_noclose(0)
00118    {
00119       if (!(fp = fopen(fname, "a"))) {
00120           fprintf(stderr, "Error: Could not open %s: %s\n", fname ? fname :
00121                   "", strerror(errno)); 
00122           sshutdown(0);
00123       }
00124       if (!(fpw = fopen(fnamew, "a"))) {
00125           fprintf(stderr, "Error: Could not open %s: %s\n", fnamew ? fnamew :
00126                   "", strerror(errno)); 
00127           sshutdown(0);
00128       }
00129       logFileName = static_cast<char *>(oalloc(strlen(fname) + 1));
00130       strcpy(logFileName, fname);
00131 
00132       logwFileName = static_cast<char *>(oalloc(strlen(fnamew) + 1));
00133       strcpy(logwFileName, fnamew);
00134     }
00135     ~SLogfile() {
00136         if (!fp_noclose)
00137              fclose(fp);
00138         free(logFileName);
00139         free(logwFileName);
00140         if (fpw && !fpw_noclose) fclose(fpw);
00141       /*if (db)
00142           db->dbclose(db);*/
00143     }
00144 
00146     void flush() {
00147          if (logwFileName && !fpw_noclose) {
00148              if ( fclose(fpw) < 0 )
00149                  dlogEntry("ERROR encountered in closing working log %s, %d", logwFileName, errno);
00150              fpw = 0;
00151              fpw = fopen(logwFileName, "a");
00152          }
00153          if (fp) fflush(fp); 
00154     }
00155 
00157     int log(UserList *sender, 
00158             interp::services_cmd_id cmd,
00159             const char *target,
00160             u_int32_t flags = 0, const char *extra = nullFmtHack, ...)
00161     __attribute__ ((format (printf, 6, 7)));
00162 
00164     int logw(UserList *sender, 
00165             interp::services_cmd_id cmd,
00166             const char *target,
00167             u_int32_t flags = 0, const char *extra = nullFmtHack, ...)
00168     __attribute__ ((format (printf, 6, 7)));
00169 
00171     int logx(UserList *sender, int, 
00172             interp::services_cmd_id cmd,
00173             const char *target,
00174             u_int32_t flags = 0, const char *extra = nullFmtHack, va_list ap = NULL);
00175 
00176 #if 0
00177     void write_log_db(const char *key, struct log_file_entry *aaa) {
00178       DBT key, value;
00179 
00180       if (!db) return;
00181 
00182       key.data = key;
00183       key.size = strlen(key);
00184       value.data = *aaa;
00185       value.size = sizeof(*aaa);
00186       db->put(db, &key, &value, 0);
00187     }
00188 #endif
00189   private:
00191    FILE *fp, *fpw;  
00192    char *logFileName, *logwFileName;
00193    char fp_noclose, fpw_noclose;
00194 
00195    /* DB *db; */
00196 };
00197 
00199 extern class SLogfile *operlog;  
00200 
00202 extern class SLogfile *nicklog;
00203 
00205 extern class SLogfile *chanlog;
00206 
00208 extern FILE           *corelog;
00209 
00210 #endif

Generated at Sat Oct 25 20:56:08 2003 for Services using Doxygen.
Services Copyr. 1996-2001 Chip Norkus, Max Byrd, Greg Poma, Michael Graff, James Hess, Dafydd James. All rights reserved See LICENSE for licensing information.