mux/src/log.cpp File Reference

#include "copyright.h"
#include "autoconf.h"
#include "config.h"
#include "externs.h"
#include <sys/types.h>
#include "command.h"

Include dependency graph for log.cpp:

Go to the source code of this file.

Functions

bool start_log (const char *primary, const char *secondary)
void end_log (void)
void log_perror (const char *primary, const char *secondary, const char *extra, const char *failing_object)
void log_text (const char *text)
void log_number (int num)
void DCL_CDECL log_printf (const char *fmt,...)
void log_name (dbref target)
void log_name_and_loc (dbref player)
static const char * OBJTYP (dbref thing)
void log_type_and_name (dbref thing)
void do_log (dbref executor, dbref caller, dbref enactor, int key, int nargs, char *whichlog, char *logtext)

Variables

NAMETAB logdata_nametab []
NAMETAB logoptions_nametab []


Function Documentation

void do_log ( dbref  executor,
dbref  caller,
dbref  enactor,
int  key,
int  nargs,
char *  whichlog,
char *  logtext 
)

Definition at line 261 of file log.cpp.

References alloc_lbuf, ENDLINE, free_lbuf, mux_isalnum, notify, pFilename, strip_ansi(), and UNUSED_PARAMETER.

00270 {
00271     UNUSED_PARAMETER(caller);
00272     UNUSED_PARAMETER(enactor);
00273     UNUSED_PARAMETER(key);
00274     UNUSED_PARAMETER(nargs);
00275 
00276     bool bValid = true;
00277 
00278     // Strip the filename of all ANSI.
00279     //
00280     char *pFilename = strip_ansi(whichlog);
00281 
00282     // Restrict filename to a subdirectory to reduce the possibility
00283     // of a security hole.
00284     //
00285     char *temp_ptr = strrchr(pFilename, '/');
00286     if (temp_ptr)
00287     {
00288         pFilename = ++temp_ptr;
00289     }
00290     temp_ptr = strrchr(pFilename, '\\');
00291     if (temp_ptr)
00292     {
00293         pFilename = ++temp_ptr;
00294     }
00295 
00296     // Check for and disallow leading periods, empty strings
00297     // and filenames over 30 characters.
00298     //
00299     size_t n = strlen(pFilename);
00300     if (  n == 0
00301        || n > 30)
00302     {
00303         bValid = false;
00304     }
00305     else
00306     {
00307         unsigned int i;
00308         for (i = 0; i < n; i++)
00309         {
00310             if (!mux_isalnum(pFilename[i]))
00311             {
00312                 bValid = false;
00313                 break;
00314             }
00315         }
00316     }
00317 
00318     char *pFullName = NULL;
00319     char *pMessage = "";
00320     if (bValid)
00321     {
00322         pFullName = alloc_lbuf("do_log_filename");
00323         sprintf(pFullName, "logs/M-%s.log", pFilename);
00324 
00325         // Strip the message of all ANSI.
00326         //
00327         pMessage = strip_ansi(logtext);
00328 
00329         // Check for and disallow empty messages.
00330         //
00331         if (pMessage[0] == '\0')
00332         {
00333             bValid = false;
00334         }
00335     }
00336     if (!bValid)
00337     {
00338         if (pFullName) free_lbuf(pFullName);
00339         notify(executor, "Syntax: @log file=message");
00340         return;
00341     }
00342 
00343     FILE *hFile = fopen(pFullName, "r");
00344     if (hFile)
00345     {
00346         fclose(hFile);
00347         hFile = fopen(pFullName, "a");
00348     }
00349     if (hFile == NULL)
00350     {
00351         notify(executor, "Not a valid log file.");
00352         if (pFullName) free_lbuf(pFullName);
00353         return;
00354     }
00355 
00356     // Okay, at this point, the file exists.
00357     //
00358     fprintf(hFile, "%s" ENDLINE, pMessage);
00359     fclose(hFile);
00360     free_lbuf(pFullName);
00361 }

void end_log ( void   ) 

Definition at line 106 of file log.cpp.

References ENDLINE, CLogFile::Flush(), Log, statedata::logging, mudstate, and CLogFile::WriteString().

Referenced by pool_alloc(), pool_alloc_lbuf(), pool_free(), pool_free_lbuf(), and report_timecheck().

00107 {
00108     Log.WriteString(ENDLINE);
00109     Log.Flush();
00110     mudstate.logging--;
00111 }

void log_name ( dbref  target  ) 

Definition at line 169 of file log.cpp.

References statedata::bStandAlone, free_lbuf, GOD, Log, confdata::log_info, LOGOPT_FLAGS, LOGOPT_OWNER, mudconf, mudstate, Name, Owner, strip_ansi(), CLogFile::tinyprintf(), unparse_object(), unparse_object_numonly(), and CLogFile::WriteString().

Referenced by CF_HAND(), check_connect(), do_backup(), do_boot(), do_fixdb(), do_global(), do_name(), do_newpassword(), do_pcreate(), do_quota(), do_restart(), do_shout(), do_shutdown(), do_toad(), failconn(), log_name_and_loc(), queue_write_LEN(), report_timecheck(), and shutdownsock().

00170 {
00171     if (mudstate.bStandAlone)
00172     {
00173         Log.tinyprintf("%s(#%d)", Name(target), target);
00174     }
00175     else
00176     {
00177         char *tp;
00178 
00179         if (mudconf.log_info & LOGOPT_FLAGS)
00180         {
00181             tp = unparse_object(GOD, target, false);
00182         }
00183         else
00184         {
00185             tp = unparse_object_numonly(target);
00186         }
00187         Log.WriteString(strip_ansi(tp));
00188         free_lbuf(tp);
00189         if (  (mudconf.log_info & LOGOPT_OWNER)
00190            && target != Owner(target))
00191         {
00192             if (mudconf.log_info & LOGOPT_FLAGS)
00193             {
00194                 tp = unparse_object(GOD, Owner(target), false);
00195             }
00196             else
00197             {
00198                 tp = unparse_object_numonly(Owner(target));
00199             }
00200             Log.tinyprintf("[%s]", strip_ansi(tp));
00201             free_lbuf(tp);
00202         }
00203     }
00204 }

void log_name_and_loc ( dbref  player  ) 

Definition at line 210 of file log.cpp.

References Has_location, Location, confdata::log_info, log_name(), log_text(), LOGOPT_LOC, and mudconf.

Referenced by check_connect(), do_boot(), do_command(), do_toad(), eval_boolexp(), process_command(), report(), and Task_RunQueueEntry().

00211 {
00212     log_name(player);
00213     if (  (mudconf.log_info & LOGOPT_LOC)
00214        && Has_location(player))
00215     {
00216         log_text(" in ");
00217         log_name(Location(player));
00218     }
00219     return;
00220 }

void log_number ( int  num  ) 

Definition at line 148 of file log.cpp.

References Log, and CLogFile::WriteInteger().

Referenced by boot_slave(), Log_header_err(), report_timecheck(), and shovechars().

00149 {
00150     Log.WriteInteger(num);
00151 }

void log_perror ( const char *  primary,
const char *  secondary,
const char *  extra,
const char *  failing_object 
)

Definition at line 117 of file log.cpp.

References ENDLINE, CLogFile::Flush(), Log, log_text(), statedata::logging, mudstate, start_log(), and CLogFile::WriteString().

Referenced by close_sockets(), dump_database_internal(), fork_and_dump(), make_nolinger(), make_nonblocking(), make_socket(), and shovechars().

00118 {
00119     start_log(primary, secondary);
00120     if (extra && *extra)
00121     {
00122         log_text("(");
00123         log_text(extra);
00124         log_text(") ");
00125     }
00126 
00127     // <Failing_object text>: <strerror() text>
00128     //
00129     Log.WriteString(failing_object);
00130     Log.WriteString(": ");
00131     Log.WriteString(strerror(errno));
00132 #ifndef WIN32
00133     Log.WriteString(ENDLINE);
00134 #endif // !WIN32
00135     Log.Flush();
00136     mudstate.logging--;
00137 }

void DCL_CDECL log_printf ( const char *  fmt,
  ... 
)

Definition at line 153 of file log.cpp.

References Log, mux_vsnprintf(), SIZEOF_LOG_BUFFER, and CLogFile::WriteBuffer().

00154 {
00155     va_list ap;
00156     va_start(ap, fmt);
00157     char aTempBuffer[SIZEOF_LOG_BUFFER];
00158     int nString = mux_vsnprintf(aTempBuffer, SIZEOF_LOG_BUFFER, fmt, ap);
00159     va_end(ap);
00160     Log.WriteBuffer(nString, aTempBuffer);
00161 }

void log_text ( const char *  text  ) 

Definition at line 143 of file log.cpp.

References Log, strip_ansi(), and CLogFile::WriteString().

Referenced by announce_connect(), announce_disconnect(), boot_slave(), CF_HAND(), cf_log_syntax(), cf_status_from_succfail(), check_connect(), do_backup(), do_boot(), do_command(), do_fixdb(), do_global(), do_link(), do_logged_out_internal(), do_mail_nuke(), do_mail_read(), do_name(), do_newpassword(), do_pcreate(), do_quota(), do_restart(), do_shout(), do_shutdown(), do_toad(), dump_database(), eval_boolexp(), failconn(), fcache_read(), fork_and_dump(), get_slave_result(), helpindex_read(), init_version(), CHashFile::Insert(), load_game(), Log_header_err(), log_name_and_loc(), log_perror(), Log_pointer_err(), log_signal(), log_signal_ignore(), Log_simple_err(), log_type_and_name(), LogStatBuf(), main(), CGuests::MakeGuestChar(), new_connection(), new_mail_message(), pool_free(), pool_free_lbuf(), process_command(), purge_going(), queue_write_LEN(), report(), report_timecheck(), ReportTopic(), shovechars(), shutdownsock(), Task_RunQueueEntry(), and ValidateHelpFileIndex().

00144 {
00145     Log.WriteString(strip_ansi(text));
00146 }

void log_type_and_name ( dbref  thing  ) 

Definition at line 245 of file log.cpp.

References Good_obj, log_text(), Name, and OBJTYP().

Referenced by Log_header_err(), Log_pointer_err(), Log_simple_err(), and purge_going().

00246 {
00247     char nbuf[16];
00248 
00249     log_text(OBJTYP(thing));
00250     sprintf(nbuf, " #%d(", thing);
00251     log_text(nbuf);
00252     if (Good_obj(thing))
00253     {
00254         log_text(Name(thing));
00255     }
00256     log_text(")");
00257     return;
00258 }

static const char* OBJTYP ( dbref  thing  )  [static]

Definition at line 222 of file log.cpp.

References Good_dbref, TYPE_EXIT, TYPE_GARBAGE, TYPE_PLAYER, TYPE_ROOM, TYPE_THING, and Typeof.

Referenced by log_type_and_name().

00223 {
00224     if (!Good_dbref(thing))
00225     {
00226         return "??OUT-OF-RANGE??";
00227     }
00228     switch (Typeof(thing))
00229     {
00230     case TYPE_PLAYER:
00231         return "PLAYER";
00232     case TYPE_THING:
00233         return "THING";
00234     case TYPE_ROOM:
00235         return "ROOM";
00236     case TYPE_EXIT:
00237         return "EXIT";
00238     case TYPE_GARBAGE:
00239         return "GARBAGE";
00240     default:
00241         return "??ILLEGAL??";
00242     }
00243 }

bool start_log ( const char *  primary,
const char *  secondary 
)

Definition at line 52 of file log.cpp.

References statedata::bStandAlone, ENDLINE, CLinearTimeAbsolute::GetLocal(), FIELDEDTIME::iDayOfMonth, FIELDEDTIME::iHour, FIELDEDTIME::iMinute, FIELDEDTIME::iMonth, FIELDEDTIME::iSecond, FIELDEDTIME::iYear, Log, confdata::log_info, statedata::logging, LOGOPT_TIMESTAMP, confdata::mud_name, mudconf, mudstate, CLinearTimeAbsolute::ReturnFields(), CLogFile::tinyprintf(), and CLogFile::WriteString().

Referenced by log_perror(), pool_alloc(), pool_alloc_lbuf(), pool_free(), pool_free_lbuf(), and report_timecheck().

00053 {
00054     mudstate.logging++;
00055     if (  1 <= mudstate.logging
00056        && mudstate.logging <= 2)
00057     {
00058         if (!mudstate.bStandAlone)
00059         {
00060             // Format the timestamp.
00061             //
00062             char buffer[256];
00063             buffer[0] = '\0';
00064             if (mudconf.log_info & LOGOPT_TIMESTAMP)
00065             {
00066                 CLinearTimeAbsolute ltaNow;
00067                 ltaNow.GetLocal();
00068                 FIELDEDTIME ft;
00069                 ltaNow.ReturnFields(&ft);
00070                 sprintf(buffer, "%d.%02d%02d:%02d%02d%02d ",ft.iYear,
00071                     ft.iMonth, ft.iDayOfMonth, ft.iHour, ft.iMinute,
00072                     ft.iSecond);
00073             }
00074 
00075             // Write the header to the log.
00076             //
00077             if (  secondary
00078                && *secondary)
00079             {
00080                 Log.tinyprintf("%s%s %3s/%-5s: ", buffer, mudconf.mud_name,
00081                     primary, secondary);
00082             }
00083             else
00084             {
00085                 Log.tinyprintf("%s%s %-9s: ", buffer, mudconf.mud_name,
00086                     primary);
00087             }
00088         }
00089 
00090         // If a recursive call, log it and return indicating no log.
00091         //
00092         if (mudstate.logging == 1)
00093         {
00094             return true;
00095         }
00096         Log.WriteString("Recursive logging request." ENDLINE);
00097     }
00098     mudstate.logging--;
00099     return false;
00100 }


Variable Documentation

NAMETAB logdata_nametab[]

Initial value:

{
    {"flags",           1,  0,  LOGOPT_FLAGS},
    {"location",        1,  0,  LOGOPT_LOC},
    {"owner",           1,  0,  LOGOPT_OWNER},
    {"timestamp",       1,  0,  LOGOPT_TIMESTAMP},
    { NULL,             0,  0,  0}
}

Definition at line 15 of file log.cpp.

Referenced by do_list().

NAMETAB logoptions_nametab[]

Initial value:

{
    {"accounting",      2,  0,  LOG_ACCOUNTING},
    {"all_commands",    2,  0,  LOG_ALLCOMMANDS},
    {"bad_commands",    2,  0,  LOG_BADCOMMANDS},
    {"buffer_alloc",    3,  0,  LOG_ALLOCATE},
    {"bugs",            3,  0,  LOG_BUGS},
    {"checkpoints",     2,  0,  LOG_DBSAVES},
    {"config_changes",  2,  0,  LOG_CONFIGMODS},
    {"create",          2,  0,  LOG_PCREATES},
    {"killing",         1,  0,  LOG_KILLS},
    {"logins",          1,  0,  LOG_LOGIN},
    {"network",         1,  0,  LOG_NET},
    {"problems",        1,  0,  LOG_PROBLEMS},
    {"security",        2,  0,  LOG_SECURITY},
    {"shouts",          2,  0,  LOG_SHOUTS},
    {"startup",         2,  0,  LOG_STARTUP},
    {"suspect",         2,  0,  LOG_SUSPECTCMDS},
    {"time_usage",      1,  0,  LOG_TIMEUSE},
    {"wizard",          1,  0,  LOG_WIZARD},
    { NULL,                     0,  0,  0}
}

Definition at line 24 of file log.cpp.

Referenced by do_list().


Generated on Mon May 28 04:40:19 2007 for MUX by  doxygen 1.4.7