00001 #ifndef __log_h__
00002 #define __log_h__
00003
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "interp.h"
00042
00043 extern const char *fullhost1(const UserList *);
00044
00048 extern const char *nullFmtHack;
00049
00050
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
00087
00088
00089
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
00142
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
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