log.cpp File Reference


Detailed Description

Handles log files.

Definition in file log.cpp.

#include <stdio.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <list>
#include <string>
#include "conf.h"
#include "stats.h"
#include "shared.h"
#include "logic.h"
#include "params.h"
#include "log.h"

Include dependency graph for log.cpp:

Go to the source code of this file.

Defines

#define FILE_SLASH   "/"

Functions

void init_echoes ()
 Initializes echoes to stdout (log_echo_XXX) form conf.txt.
string irc_to_upper (string str)
 Converts string to UPPER case (using touppertab[] in match.cpp).
void log_bot (const char *msg)
 Writes debug string to file logs/bot.log and to stdout if log_echo_bot == true.
void log_botnet (const char *myname, const char *remote_name, const char *msg)
 Writes error message of origin botnet.
void log_botnet_debug (const char *myname, const char *remote_name, int packet_type, int command, const char *msg)
 Writes error message of origin botnet (botnet debug messages).
void log_broadcast (string bcast_mask, int type, string who, string msg, string server, unsigned short server_port)
 Writes string to file logs/broadcast.log and to stdout if log_echo_broadcast == true.
void log_channel (const char *channel, int type, const char *who, const char *whom, const char *msg, const char *user_modes)
 Writes debug string to file logs/#channel_name.log, or logs/status.log and to stdout if log_echo_channel == true.
void log_debug (const char *msg)
 Writes debug string to file logs/debug.log and to stdout if log_echo_debug == true.
string log_done (int exit_code, string eol)
 Shuts down the log files.
void log_free_locks ()
 Frees the lock files.
void log_identd (const char *msg)
 Writes debug string to file logs/identd.log and to stdout if log_echo_identd == true.
bool log_init ()
 Inits the log files.
void log_irc (bool from_server, const char *msg)
 Writes debug string to file logs/irc.log and to stdout if log_echo_irc == true.
void log_socket (int sock_error, const char *os_msg, const char *msg)
 Writes debug string to file logs/socket.log and to stdout if log_echo_socket == true.
void log_ssl (const char *msg)
 Writes debug string to file logs/ssl.log and to stdout if log_echo_ssl == true.
char * ltoa (long value, char *buffer, int radix)
 ltoa() emulation for compiler which doesn't have it

Variables

bool log_bot_ = true
 Set this to true if BOT log messages should be written to file.
bool log_botnet_ = true
 Set this to true if BOTNET log messages should be written to file.
bool log_botnet_debug_ = true
 Set this to true if BOTNET debug log messages should be written to file.
bool log_broadcast_ = true
 Set this to true if broadcasted messages from IRC operators should be written to file.
bool log_debug_ = true
 Set this to true if DEBUG log messages should be written to file.
bool log_echo_bot = true
 Set this to true if BOT log messages should be echoed to stdout in console.
bool log_echo_botnet = true
 Set this to true if BOTNET log messages should be echoed to stdout in console.
bool log_echo_botnet_debug = true
 Set this to true if BOTNET debug log messages should be echoed to stdout in console.
bool log_echo_broadcast = true
 Set this to true if broadcasted messages from IRC operators should be echoed to stdout in console.
bool log_echo_debug = true
 Set this to true if DEBUG log messages should be echoed to stdout in console.
bool log_echo_identd = true
 Set this to true if IDENTD log messages should be echoed to stdout in console.
bool log_echo_irc = true
 Set this to true if IRC log messages should be echoed to stdout in console.
bool log_echo_socket = true
 Set this to true if SOCKET log messages should be echoed to stdout in console.
bool log_echo_ssl = true
 Set this to true if SSL debug log messages should be echoed to stdout in console.
bool log_identd_ = true
 Set this to true if IDENTD log messages should be written to file.
bool log_initialized = false
 Was echoes/logs initialized?
bool log_irc_ = true
 Set this to true if IRC log messages should be written to file.
bool log_socket_ = true
 Set this to true if SOCKET log messages should be written to file.
bool log_ssl_ = true
 Set this to true if SSL debug log messages should be written to file.
FILE * pid = NULL
 .pid file handle
int posix_lock_file = -1
 .lock file handle (Unices only), or -1 for problems = should be ignored to close()


Define Documentation

#define FILE_SLASH   "/"
 

Definition at line 81 of file log.cpp.


Function Documentation

void init_echoes  ) 
 

Initializes echoes to stdout (log_echo_XXX) form conf.txt.

Definition at line 122 of file log.cpp.

References conf_getvar(), log_bot_, log_botnet_, log_botnet_debug_, log_broadcast_, log_debug_, log_echo_bot, log_echo_botnet, log_echo_botnet_debug, log_echo_broadcast, log_echo_debug, log_echo_identd, log_echo_irc, log_echo_socket, log_echo_ssl, log_identd_, log_initialized, log_irc_, log_socket_, and log_ssl_.

Referenced by log_bot(), log_botnet(), log_botnet_debug(), log_broadcast(), log_channel(), log_debug(), log_identd(), log_irc(), log_socket(), and log_ssl().

00123 {
00124     log_initialized=true;
00125     log_echo_debug=atol(conf_getvar("log_echo_debug").c_str())!=0;
00126     log_echo_irc=atol(conf_getvar("log_echo_irc").c_str())!=0;
00127     log_echo_socket=atol(conf_getvar("log_echo_socket").c_str())!=0;
00128     log_echo_bot=atol(conf_getvar("log_echo_bot").c_str())!=0;
00129     log_echo_identd=atol(conf_getvar("log_echo_identd").c_str())!=0;
00130     log_echo_botnet=atol(conf_getvar("log_echo_botnet").c_str())!=0;
00131     log_echo_botnet_debug=atol(conf_getvar("log_echo_botnet_debug").c_str())!=0;
00132     log_echo_ssl=atol(conf_getvar("log_echo_ssl").c_str())!=0;
00133     log_echo_broadcast=atol(conf_getvar("log_echo_broadcast").c_str())!=0;
00134 
00135     log_debug_=atol(conf_getvar("log_debug").c_str())!=0;
00136     log_irc_=atol(conf_getvar("log_irc").c_str())!=0;
00137     log_socket_=atol(conf_getvar("log_socket").c_str())!=0;
00138     log_bot_=atol(conf_getvar("log_bot").c_str())!=0;
00139     log_identd_=atol(conf_getvar("log_identd").c_str())!=0;
00140     log_botnet_=atol(conf_getvar("log_botnet").c_str())!=0;
00141     log_botnet_debug_=atol(conf_getvar("log_botnet_debug").c_str())!=0;
00142     log_ssl_=atol(conf_getvar("log_ssl").c_str())!=0;
00143     log_broadcast_=atol(conf_getvar("log_broadcast").c_str())!=0;
00144 
00145 #ifdef _WIN32
00146     mkdir("logs");
00147 #else
00148     mkdir("./logs",0700);
00149 #endif
00150 }

Here is the call graph for this function:

string irc_to_upper string  str  ) 
 

Converts string to UPPER case (using touppertab[] in match.cpp).

Author:
VooDooMan
Version:
1
Date:
2004
Parameters:
str Source string
Returns:
Returns UPPERcase string (using touppertab[] in match.cpp)

Definition at line 269 of file irc.cpp.

References touppertab.

Referenced by cmp_strings_case_insensitive().

00270 {
00271     extern unsigned char touppertab[];
00272 
00273     string res;
00274     for(unsigned int i1=0; i1<str.length(); i1++)
00275         res+=touppertab[str[i1]];
00276     return res;
00277 }

void log_bot const char *  msg  ) 
 

Writes debug string to file logs/bot.log and to stdout if log_echo_bot == true.

Author:
VooDooMan
Version:
1
Date:
2004
Parameters:
msg The log message

Definition at line 253 of file log.cpp.

References FILE_SLASH, init_echoes(), log_bot_, log_echo_bot, log_initialized, logic_on_internal_event(), and PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL.

Referenced by dcc_loop(), dcc_upgrade(), irc_loop_process_input(), irc_quoted_callback(), log_done(), log_init(), logic_botnet_rehash(), logic_exec(), logic_partyline_backup(), logic_partyline_rehash(), logic_rehash(), logic_rollback(), main(), and write_kill_log().

00254 {
00255     if(!log_initialized)
00256         init_echoes();
00257 
00258     if(log_bot_) {
00259         FILE* f=fopen("logs" FILE_SLASH "bot.log","a");
00260         if(f) {
00261             char now[128];
00262             time_t n=time(NULL);
00263             strcpy(now,ctime(&n));
00264             now[26-1-1]=0;
00265             fprintf(f,"%s%s%s\n",now,": ",msg);
00266             fclose(f);
00267         }
00268     }
00269 
00270     if(log_echo_bot)
00271         printf("%s%s\n","BOT     ",msg);
00272 
00273     logic_on_internal_event("@log@","bot","","","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,msg,"");
00274 }

Here is the call graph for this function:

void log_botnet const char *  myname,
const char *  remote_name,
const char *  msg
 

Writes error message of origin botnet.

Author:
VooDooMan
Version:
1
Date:
2004
Parameters:
myname Name of this bot
remote_name Name of remote bot
msg The log message

Definition at line 494 of file log.cpp.

References FILE_SLASH, init_echoes(), log_botnet_, log_echo_botnet, log_initialized, logic_on_internal_event(), and PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL.

Referenced by botnet_loop(), botnet_push_chan(), botnet_push_proc(), botnet_push_prv(), botnet_push_user(), botnet_receive(), and log_init().

00495 {
00496     if(!log_initialized)
00497         init_echoes();
00498 
00499     if(log_botnet_) {
00500         FILE* f=fopen("logs" FILE_SLASH "botnet.log","a");
00501         if(f) {
00502             char now[128];
00503             time_t n=time(NULL);
00504             strcpy(now,ctime(&n));
00505             now[26-1-1]=0;
00506             fprintf(f,"%s * %s->%s %s\n",now,myname,remote_name,msg);
00507             fclose(f);
00508         }
00509     }
00510 
00511     if(log_echo_botnet)
00512         printf("BOTNET  %s->%s %s\n",myname,remote_name,msg);
00513 
00514     logic_on_internal_event("@log@","botnet",remote_name,"","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,msg,"");
00515 }

Here is the call graph for this function:

void log_botnet_debug const char *  myname,
const char *  remote_name,
int  packet_type,
int  command,
const char *  msg
 

Writes error message of origin botnet (botnet debug messages).

Author:
VooDooMan
Version:
1
Date:
2004
Parameters:
myname Name of this bot
remote_name Name of remote bot
packet_type Type of packet
command Command number
msg The log message

Definition at line 458 of file log.cpp.

References FILE_SLASH, init_echoes(), log_botnet_debug_, log_echo_botnet_debug, log_initialized, logic_on_internal_event(), and PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL.

Referenced by botnet_loop(), botnet_push_chan(), botnet_push_proc(), botnet_push_prv(), botnet_push_user(), botnet_send_command(), botnet_send_control(), and log_init().

00459 {
00460     if(!log_initialized)
00461         init_echoes();
00462 
00463     if(log_botnet_debug_) {
00464         FILE* f=fopen("logs" FILE_SLASH "botnet_debug.log","a");
00465         if(f) {
00466             char now[128];
00467             time_t n=time(NULL);
00468             strcpy(now,ctime(&n));
00469             now[26-1-1]=0;
00470             fprintf(f,"%s * MyName=%s RemoteName=%s PacketType=%d Command=%d * %s\n",now,myname,remote_name,packet_type,command,msg);
00471             fclose(f);
00472         }
00473     }
00474 
00475     if(log_echo_botnet_debug)
00476         printf("BOTNET  MyName=%s RemoteName=%s PacketType=%d Command=%d * %s\n",myname,remote_name,packet_type,command,msg);
00477 
00478     char* final_msg=new char[strlen(myname)+strlen(remote_name)+strlen(msg)+10*1024];
00479     sprintf(final_msg,"BOTNET  MyName=%s RemoteName=%s PacketType=%d Command=%d * %s",myname,remote_name,packet_type,command,msg);
00480     logic_on_internal_event("@log@","botnet_debug",remote_name,"","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,final_msg,"");
00481     delete[] final_msg;
00482     final_msg=NULL;
00483 }

Here is the call graph for this function:

void log_broadcast string  bcast_mask,
int  type,
string  who,
string  msg,
string  server,
unsigned short  server_port
 

Writes string to file logs/broadcast.log and to stdout if log_echo_broadcast == true.

Author:
VooDooMan
Version:
1
Date:
2005-04-22
Parameters:
bcast_mask Broadcast mask used (something like "$$irc.nonexistingdomain.org")
type Type of message: TYPE_PRIVMSG, TYPE_NOTICE; TODO: KILL
who For type == TYPE_PRIVMSG, or TYPE_NOTICE ("nick!ident@host") of originator of message (most likely an irc op)
msg Message
server Server DNS host we are using now
server_port Port of IRC server we are on

Definition at line 750 of file log.cpp.

References FILE_SLASH, init_echoes(), log_initialized, logic_on_internal_event(), PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL, TYPE_NOTICE, and TYPE_PRIVMSG.

Referenced by irc_loop_process_input().

00751 {
00752     if(!log_initialized)
00753         init_echoes();
00754 
00755     char* host_str=new char[server.length()+512];
00756     bool _ipv6=server.find(":",0)!=string::npos;
00757     host_str[0]=0;
00758     if(_ipv6)
00759         strcat(host_str,"[");
00760     strcat(host_str,server.c_str());
00761     if(_ipv6)
00762         strcat(host_str,"]");
00763     strcat(host_str,":");
00764     char tmp2[512];
00765     sprintf(tmp2,"%u",(unsigned)server_port);
00766     strcat(host_str,tmp2);
00767 
00768     char tmp[1024];
00769     strcpy(tmp,"logs" FILE_SLASH);
00770     strcat(tmp,"broadcast");
00771     strcat(tmp,".log");
00772 
00773     char* final_msg=new char[who.length()+bcast_mask.length()+strlen(host_str)+msg.length()+10*1024];
00774     final_msg[0]=0;
00775 
00776     FILE* f=fopen(tmp,"a+");
00777     if(f) {
00778         time_t n=time(NULL);
00779         strcpy(tmp,ctime(&n));
00780         tmp[26-1-1]=0;
00781         switch(type) {
00782             case TYPE_PRIVMSG:
00783                 fprintf(f,"%s <%s> PRIVMSG %s (using server %s): %s\n",tmp,who.c_str(),bcast_mask.c_str(),host_str,msg.c_str());
00784                 sprintf(final_msg,"%s <%s> PRIVMSG %s (using server %s): %s",tmp,who.c_str(),bcast_mask.c_str(),host_str,msg.c_str());
00785                 break;
00786             case TYPE_NOTICE:
00787                 fprintf(f,"%s <%s> NOTICE %s (using server %s): %s\n",tmp,who.c_str(),bcast_mask.c_str(),host_str,msg.c_str());
00788                 sprintf(final_msg,"%s <%s> NOTICE %s (using server %s): %s",tmp,who.c_str(),bcast_mask.c_str(),host_str,msg.c_str());
00789                 break;
00790             // TODO: case KILL
00791             default:
00792                 break;
00793         }
00794         fclose(f);
00795     }
00796 
00797     if(final_msg[0])
00798         logic_on_internal_event("@log@","broadcast",who,"","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,final_msg,"");
00799 
00800     delete[] final_msg;
00801     final_msg=NULL;
00802 
00803     delete[] host_str;
00804     host_str=NULL;
00805 }

Here is the call graph for this function:

void log_channel const char *  channel,
int  type,
const char *  who,
const char *  whom,
const char *  msg,
const char *  user_modes
 

Writes debug string to file logs/#channel_name.log, or logs/status.log and to stdout if log_echo_channel == true.

Author:
VooDooMan
Version:
2
Date:
2004, 2005
Parameters:
channel Channel name, or empty string for message to logs/status.log
type Type of message: TYPE_PRIVMSG, TYPE_NOTICE, TYPE_JOIN, TYPE_PART, TYPE_QUIT, TYPE_KICK, TYPE_MODE, TYPE_NICK, TYPE_SCRIPT, TYPE_IRCOP_JOIN, TYPE_IRCOP_LEFT
who For type == TYPE_PRIVMSG, or TYPE_NOTICE, or TYPE_JOIN, or TYPE_PART, or TYPE_QUIT, TYPE_KICK, TYPE_MODE host string ("nick!ident@host") of originator of message, and for type TYPE_NICK host string with old nick name
whom For type == TYPE_NOTICE who is target (channel name or bot's nick), or for type == TYPE_KICK nick of target
msg For type == TYPE_PRIVMSG, or TYPE_NOTICE, or TYPE_PART, or TYPE_KICK, or TYPE_QUIT message, or for type == TYPE_MODE MODE string (i.e. "+b *!*@*.gov), or for type == TYPE_SCRIPT message from script result, or for type == TYPE_TOPIC it is new topic
user_modes Mode(s) of user (e.g. "v", "o", "h", "vo",...), or single character long string "?" for not-got-WHOIS-yet

Definition at line 318 of file log.cpp.

References FILE_SLASH, init_echoes(), log_initialized, logic_on_internal_event(), PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL, tolowertab, TYPE_IRCOP_JOIN, TYPE_IRCOP_LEFT, TYPE_JOIN, TYPE_KICK, TYPE_MODE, TYPE_NICK, TYPE_NOTICE, TYPE_PART, TYPE_PRIVMSG, TYPE_QUIT, TYPE_SCRIPT, and TYPE_TOPIC.

Referenced by irc_loop_process_input(), irc_RPL_WHOISOPERATOR(), and logic_process_script_output().

00319 {
00320     if(!log_initialized)
00321         init_echoes();
00322 
00323     if(strlen(channel)>128)
00324         return;
00325 
00326     char ch[1024];
00327     memset(ch,0,1024);
00328     strncpy(ch,channel,1024-1);
00329 
00330     for(unsigned int i1=0; i1<strlen(ch); i1++) {
00331         extern unsigned char tolowertab[];
00332         ch[i1]=tolowertab[ch[i1]];
00333         unsigned char* tmp=(unsigned char*)&ch[i1];
00334         if(*tmp<32 || *tmp>159 || *tmp=='*' || *tmp=='/' || *tmp==':' ||
00335            *tmp=='<' || *tmp=='>' || *tmp=='?' || *tmp=='\\' || *tmp=='|')
00336            *tmp='_';
00337     }
00338 
00339     char tmp[1024];
00340     strcpy(tmp,"logs" FILE_SLASH);
00341     if(*ch)
00342         strcat(tmp,ch);
00343         else
00344         strcat(tmp,"status");
00345     strcat(tmp,".log");
00346 
00347     char modes[128];
00348     unsigned ii2=0;
00349     modes[ii2++]='[';
00350     bool first=true;
00351     for(unsigned ii=0; ii<128-16 && user_modes[ii]!=0; ii++) {
00352         if(ii==0 && (type==TYPE_IRCOP_JOIN || type==TYPE_IRCOP_LEFT) && user_modes[ii]!='!')
00353             modes[ii2++]='!';
00354         if(first) {
00355             if(ii==0 && user_modes[ii]=='?') {
00356                 first=false;
00357                 continue;
00358             }
00359             if(ii==0 && user_modes[ii]=='!') {
00360                 first=true;
00361                 modes[ii2++]='!';
00362                 continue;
00363             }
00364             modes[ii2++]='+';
00365             first=false;
00366         }
00367         modes[ii2++]=user_modes[ii];
00368     }
00369     while(ii2<8+2-1) // (8 chars) + (one * '[') + (one * ']') - (1 coz it's zero-based index)
00370         modes[ii2++]=0x20;
00371     modes[ii2++]=']';
00372     modes[ii2++]=0;
00373 
00374     char* final_msg=new char[strlen(msg)+strlen(channel)+10*1024];
00375     final_msg[0]=0;
00376 
00377     FILE* f=fopen(tmp,"a+");
00378     if(f) {
00379         time_t n=time(NULL);
00380         strcpy(tmp,ctime(&n));
00381         tmp[26-1-1]=0;
00382         switch(type) {
00383             case TYPE_PRIVMSG:
00384                 fprintf(f,"%s PRIVMSG %s <%s> :%s\n",tmp,modes,who,msg);
00385                 sprintf(final_msg,"%s PRIVMSG %s <%s> :%s",tmp,modes,who,msg);
00386                 break;
00387             case TYPE_NOTICE:
00388                 fprintf(f,"%s NOTICE  %s <%s> %s :%s\n",tmp,modes,who,whom,msg);
00389                 sprintf(final_msg,"%s NOTICE  %s <%s> %s :%s",tmp,modes,who,whom,msg);
00390                 break;
00391             case TYPE_JOIN:
00392                 fprintf(f,"%s JOIN    %s <%s> %s\n",tmp,modes,who,channel);
00393                 sprintf(final_msg,"%s JOIN    %s <%s> %s",tmp,modes,who,channel);
00394                 break;
00395             case TYPE_PART:
00396                 fprintf(f,"%s PART    %s <%s> %s :%s\n",tmp,modes,who,channel,msg);
00397                 sprintf(final_msg,"%s PART    %s <%s> %s :%s",tmp,modes,who,channel,msg);
00398                 break;
00399             case TYPE_QUIT:
00400                 fprintf(f,"%s QUIT    %s <%s> :%s\n",tmp,modes,who,msg);
00401                 sprintf(final_msg,"%s QUIT    %s <%s> :%s",tmp,modes,who,msg);
00402                 break;
00403             case TYPE_KICK:
00404                 fprintf(f,"%s KICK    %s <%s> %s :%s\n",tmp,modes,who,whom,msg);
00405                 sprintf(final_msg,"%s KICK    %s <%s> %s :%s",tmp,modes,who,whom,msg);
00406                 break;
00407             case TYPE_MODE:
00408                 fprintf(f,"%s MODE    %s <%s> %s\n",tmp,modes,who,msg);
00409                 sprintf(final_msg,"%s MODE    %s <%s> %s",tmp,modes,who,msg);
00410                 break;
00411             case TYPE_NICK:
00412                 fprintf(f,"%s NICK    %s <%s> :%s\n",tmp,modes,who,msg);
00413                 sprintf(final_msg,"%s NICK    %s <%s> :%s",tmp,modes,who,msg);
00414                 break;
00415             case TYPE_SCRIPT:
00416                 fprintf(f,"%s SCRIPT: %s\n",tmp,msg);
00417                 sprintf(final_msg,"%s SCRIPT: %s",tmp,msg);
00418                 break;
00419             case TYPE_TOPIC:
00420                 fprintf(f,"%s TOPIC   %s <%s> %s :%s\n",tmp,modes,who,channel,msg);
00421                 sprintf(final_msg,"%s TOPIC   %s <%s> %s :%s",tmp,modes,who,channel,msg);
00422                 break;
00423             case TYPE_IRCOP_JOIN:
00424                 fprintf(f,"%s IRCOP+  %s <%s> Is an IRC operator on channel %s\n",tmp,modes,who,channel);
00425                 sprintf(final_msg,"%s IRCOP+  %s <%s> Is an IRC operator on channel %s",tmp,modes,who,channel);
00426                 break;
00427             case TYPE_IRCOP_LEFT:
00428                 fprintf(f,"%s IRCOP-  %s <%s> Was an IRC operator on channel %s\n",tmp,modes,who,channel);
00429                 sprintf(final_msg,"%s IRCOP-  %s <%s> Was an IRC operator on channel %s",tmp,modes,who,channel);
00430                 break;
00431             default:
00432                 break;
00433         }
00434         fclose(f);
00435     }
00436 
00437     string chnl=channel;
00438     if(chnl.empty())
00439         chnl="status";
00440     if(final_msg[0])
00441         logic_on_internal_event("@log@","channel",chnl,"","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,final_msg,"");
00442 
00443     delete[] final_msg;
00444     final_msg=NULL;
00445 }

Here is the call graph for this function:

void log_debug const char *  msg  ) 
 

Writes debug string to file logs/debug.log and to stdout if log_echo_debug == true.

Author:
VooDooMan
Version:
1
Date:
2004
Parameters:
msg The log message

Definition at line 159 of file log.cpp.

References FILE_SLASH, init_echoes(), log_debug_, log_echo_debug, log_initialized, logic_on_internal_event(), and PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL.

Referenced by botnet_link(), botnet_receive(), botnet_send_command(), botnet_send_control(), dcc_loop(), dcc_loop_edit_user1(), dcc_loop_edit_user2(), s_bot_command::flip(), handler_sigpipe(), irc_loop_process_input(), irc_loop_putserv(), irc_mode_change_ban(), irc_mode_change_ban_exception(), irc_mode_change_chan_key(), irc_mode_change_chan_limit(), irc_mode_change_chan_status(), irc_mode_change_creator(), irc_mode_change_op(), irc_mode_change_other(), irc_mode_change_voice(), irc_putserv_immediately(), irc_quoted_callback(), irc_RPL_324(), irc_RPL_MODE(), lang_01_init(), lang_get_string(), lang_subst(), log_init(), logic_call_proc_ex(), logic_eval(), logic_exec(), logic_exec_script(), logic_list_proc(), and logic_process_script_output().

00160 {
00161     if(!log_initialized)
00162         init_echoes();
00163 
00164     if(log_debug_) {
00165         FILE* f=fopen("logs" FILE_SLASH "debug.log","a");
00166         if(f) {
00167             char now[128];
00168             time_t n=time(NULL);
00169             strcpy(now,ctime(&n));
00170             now[26-1-1]=0;
00171             fprintf(f,"%s%s%s\n",now,": ",msg);
00172             fclose(f);
00173         }
00174     }
00175 
00176     if(log_echo_debug)
00177         printf("%s%s\n","DEBUG   ",msg);
00178 
00179     logic_on_internal_event("@log@","debug","","","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,msg,"");
00180 }

Here is the call graph for this function:

string log_done int  exit_code,
string  eol
 

Shuts down the log files.

Author:
VooDooMan
Version:
1
Date:
2004
Parameters:
exit_code Exit code for bot used to write it to log
eol EOL string for user who is killing the bot (only if it is a real user, not "root")
Returns:
Returns kill log using EOL as end-of-line marker for user who is killing the bot

Definition at line 694 of file log.cpp.

References dcc_want_to_restart, dcc_want_to_upgrade, log_bot(), log_free_locks(), log_initialized, and stats_display().

Referenced by main().

00695 {
00696     extern bool dcc_want_to_upgrade;
00697     extern bool dcc_want_to_restart;
00698     string res;
00699     if(log_initialized) {
00700         if(!dcc_want_to_upgrade && !dcc_want_to_restart)
00701             log_bot("*** Statistics");
00702         else
00703             log_bot("*** [previous instance] Statistics");
00704 
00705         if(!dcc_want_to_upgrade && !dcc_want_to_restart)
00706             res+="*** Statistics"+eol;
00707         else
00708             res+="*** [previous instance] Statistics"+eol;
00709         list<string> lines;
00710         stats_display(lines,"");
00711         list<string>::iterator i1=lines.begin();
00712         for(; i1!=lines.end(); i1++) {
00713             string ln;
00714             if(!dcc_want_to_upgrade && !dcc_want_to_restart) {
00715                 ln=(string)"*** "+*i1;
00716                 res+=(string)"*** "+*i1+eol;
00717             } else {
00718                 ln=(string)"*** [previous instance] "+*i1;
00719                 res+=(string)"*** [previous instance] "+*i1+eol;
00720             }
00721             log_bot(ln.c_str());
00722         }
00723 
00724         char msg[1024];
00725         if(!dcc_want_to_upgrade && !dcc_want_to_restart)
00726             sprintf(msg,"Exiting normally with exit code %d",exit_code);
00727         else
00728             sprintf(msg,"[previous instance] Exiting normally with exit code %d",exit_code);
00729         log_bot(msg);
00730         res+=(string)msg+eol;
00731     }
00732 
00733     log_free_locks();
00734 
00735     return res;
00736 }

Here is the call graph for this function:

void log_free_locks  ) 
 

Frees the lock files.

Author:
VooDooMan
Version:
1
Date:
2005

Definition at line 668 of file log.cpp.

References FILE_SLASH, pid, and posix_lock_file.

Referenced by dcc_loop(), dcc_upgrade(), and log_done().

00669 {
00670     static bool freed=false;
00671     if(freed)
00672         return;
00673     freed=true;
00674     if(pid)
00675         fclose(pid);
00676     pid=NULL;
00677     if(posix_lock_file!=-1) {
00678         close(posix_lock_file);
00679         unlink("logs" FILE_SLASH "irc_bot.lock");
00680     }
00681     posix_lock_file=-1;
00682     unlink("logs" FILE_SLASH "irc_bot.pid");
00683 }

void log_identd const char *  msg  ) 
 

Writes debug string to file logs/identd.log and to stdout if log_echo_identd == true.

Author:
VooDooMan
Version:
1
Date:
2004
Parameters:
msg The log message

Definition at line 283 of file log.cpp.

References FILE_SLASH, init_echoes(), log_echo_identd, log_identd_, log_initialized, logic_on_internal_event(), and PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL.

Referenced by identd4_shutdown(), identd6_shutdown(), identd_check(), identd_error_log(), identd_shutdown(), and identd_startup().

00284 {
00285     if(!log_initialized)
00286         init_echoes();
00287 
00288     if(log_identd_) {
00289         FILE* f=fopen("logs" FILE_SLASH "identd.log","a");
00290         if(f) {
00291             char now[128];
00292             time_t n=time(NULL);
00293             strcpy(now,ctime(&n));
00294             now[26-1-1]=0;
00295             fprintf(f,"%s%s%s\n",now,": ",msg);
00296             fclose(f);
00297         }
00298     }
00299 
00300     if(log_echo_identd)
00301         printf("%s%s\n","IDENTD  ",msg);
00302 
00303     logic_on_internal_event("@log@","identd","","","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,msg,"");
00304 }

Here is the call graph for this function:

bool log_init  ) 
 

Inits the log files.

Author:
VooDooMan
Version:
1
Date:
2004
Return values:
true If success
false If another instance is running (file "logs/irc_bot.pid" is blocked for unlink-ing)

Definition at line 568 of file log.cpp.

References FILE_SLASH, log_bot(), log_botnet(), log_botnet_debug(), log_debug(), log_initialized, log_irc(), log_socket(), pid, and posix_lock_file.

Referenced by main().

00569 {
00570 #ifdef _WIN32
00571     mkdir("logs");
00572 #else
00573     mkdir("./logs",0700);
00574 #endif
00575 
00576 #ifndef _WIN32
00577     int fd=open("logs" FILE_SLASH "irc_bot.lock",O_RDWR | O_CREAT);
00578     if(fd<0) {
00579         fd=-1;
00580         char* tmp=new char[strlen(strerror(errno))+1024];
00581         sprintf(tmp,"Error while open() #1 - LOCK file: %s",strerror(errno));
00582         log_bot(tmp);
00583         delete[] tmp;
00584     } else {
00585         struct flock lck;
00586         lck.l_type=F_RDLCK;
00587         lck.l_start=0;
00588         lck.l_whence=SEEK_SET;
00589         lck.l_len=0;
00590         lck.l_pid=0;
00591         int ec=fcntl(fd,F_GETLK,&lck);
00592         if(ec) {
00593             char* tmp=new char[strlen(strerror(errno))+1024];
00594             sprintf(tmp,"Error while fcntl() - getting lock parameters on LOCK file: %s",strerror(errno));
00595             log_bot(tmp);
00596             delete[] tmp;
00597         }
00598         if(ec==0 && lck.l_type!=F_UNLCK) {
00599             close(fd);
00600             return false;
00601         }
00602     
00603         char tmp[1024];
00604         sprintf(tmp,"%d\n",getpid());
00605         write(fd,tmp,strlen(tmp));
00606         close(fd);
00607         chmod("logs" FILE_SLASH "irc_bot.lock",0600);
00608         fd=open("logs" FILE_SLASH "irc_bot.lock",O_RDWR);
00609         if(fd<0) {
00610             fd=-1;
00611             char* tmp=new char[strlen(strerror(errno))+1024];
00612             sprintf(tmp,"Error while open() #2 - LOCK file: %s",strerror(errno));
00613             log_bot(tmp);
00614             delete[] tmp;
00615         } else {
00616             struct flock lck;
00617             lck.l_type=F_WRLCK;
00618             lck.l_start=strlen(tmp)-1;
00619             lck.l_whence=SEEK_SET;
00620             lck.l_len=1;
00621             lck.l_pid=getpid();
00622             int ec=fcntl(fd,F_SETLK,&lck);
00623             if(ec) {
00624                 char* tmp=new char[strlen(strerror(errno))+1024];
00625                 sprintf(tmp,"Error while fcntl() - setting lock parameters on LOCK file: %s",strerror(errno));
00626                 log_bot(tmp);
00627                 delete[] tmp;
00628             }
00629         }
00630     }
00631     posix_lock_file=fd;
00632 #endif
00633     {
00634         // erase test (works only on Win32!)
00635         int ec=unlink("logs" FILE_SLASH "irc_bot.pid");
00636         if(ec!=0 && errno==EACCES)
00637             return false;
00638     }
00639     FILE* f=fopen("logs" FILE_SLASH "irc_bot.pid","w");
00640     if(f) {
00641         fprintf(f,"%d\n",getpid());
00642         fclose(f);
00643         pid=fopen("logs" FILE_SLASH "irc_bot.pid","r");
00644     }
00645 
00646     if(!log_initialized) {
00647         char msg[1024];
00648         sprintf(msg,"Bot's pid is %d",getpid());
00649         log_bot(msg);
00650     }
00651 
00652     log_debug("BOT STARTUP!");
00653     log_irc(false,"BOT STARTUP!");
00654     log_socket(0,"","BOT STARTUP!");
00655     log_bot("BOT STARTUP!");
00656     log_botnet_debug("","",-1,-1,"BOT STARTUP!");
00657     log_botnet("","","BOT STARTUP!");
00658 
00659     return true;
00660 }

Here is the call graph for this function:

void log_irc bool  from_server,
const char *  msg
 

Writes debug string to file logs/irc.log and to stdout if log_echo_irc == true.

Author:
VooDooMan
Version:
1
Date:
2004
Parameters:
from_server Set to true if message goes from server, false if it goes to server
msg The log message

Definition at line 190 of file log.cpp.

References FILE_SLASH, init_echoes(), log_echo_irc, log_initialized, log_irc_, logic_on_internal_event(), and PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL.

Referenced by irc_connect(), irc_disconnect(), irc_loop_process_input(), irc_putserv_immediately(), log_init(), and logic_exec().

00191 {
00192     if(!log_initialized)
00193         init_echoes();
00194 
00195     if(log_irc_) {
00196         FILE* f=fopen("logs" FILE_SLASH "irc.log","a");
00197         if(f) {
00198             char now[128];
00199             time_t n=time(NULL);
00200             strcpy(now,ctime(&n));
00201             now[26-1-1]=0;
00202             fprintf(f,"%s%s%s%s%s\n",now," - ",(from_server?"IN ":"OUT")," : ",msg);
00203             fclose(f);
00204         }
00205     }
00206 
00207     if(log_echo_irc)
00208         printf("%s%s%s%s\n","IRC ",(from_server?"IN ":"OUT")," ",msg);
00209 
00210     logic_on_internal_event("@log@","irc",(from_server?"IN":"OUT"),"","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,msg,"");
00211 }

Here is the call graph for this function:

void log_socket int  sock_error,
const char *  os_msg,
const char *  msg
 

Writes debug string to file logs/socket.log and to stdout if log_echo_socket == true.

Author:
VooDooMan
Version:
1
Date:
2004
Parameters:
sock_error OS's socket I/O error code
os_msg Message from OS describing socket I/O error
msg The log message

Definition at line 222 of file log.cpp.

References FILE_SLASH, init_echoes(), log_echo_socket, log_initialized, log_socket_, logic_on_internal_event(), ltoa(), and PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL.

Referenced by botnet_loop(), botnet_send_command(), botnet_send_control(), dcc_loop(), dcc_make_server(), dcc_make_telnet_server(), irc_connect(), irc_loop_putserv(), irc_putserv_immediately(), irc_quoted_callback(), log_init(), sock_bind6(), sock_connect(), sock_resolve6(), and sock_reverse().

00223 {
00224     if(!log_initialized)
00225         init_echoes();
00226 
00227     if(log_socket_) {
00228         FILE* f=fopen("logs" FILE_SLASH "socket.log","a");
00229         if(f) {
00230             char now[128];
00231             time_t n=time(NULL);
00232             strcpy(now,ctime(&n));
00233             now[26-1-1]=0;
00234             fprintf(f,"%s%s%d%s%s%s%s%s\n",now,": OS socket error code: ",sock_error," ",os_msg," (",msg,")");
00235             fclose(f);
00236         }
00237     }
00238 
00239     if(log_echo_socket)
00240         printf("%s%s - %s\n","SOCKET  ",os_msg,msg);
00241 
00242     char tmp[128];
00243     logic_on_internal_event("@log@","socket",ltoa((long)sock_error,tmp,10),"","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,os_msg,msg);
00244 }

Here is the call graph for this function:

void log_ssl const char *  msg  ) 
 

Writes debug string to file logs/ssl.log and to stdout if log_echo_ssl == true.

Author:
VooDooMan
Version:
1
Date:
2004
Parameters:
msg The log message

Definition at line 524 of file log.cpp.

References FILE_SLASH, init_echoes(), log_echo_ssl, log_initialized, log_ssl_, logic_on_internal_event(), and PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL.

Referenced by ssl_client_connection(), ssl_do_read_write(), ssl_init(), ssl_process_error_on_verify(), ssl_server_connection(), ssl_server_read(), and ssl_write().

00525 {
00526     if(!log_initialized)
00527         init_echoes();
00528 
00529     char* msg2=new char[strlen(msg)+1];
00530     strcpy(msg2,msg);
00531     if(msg2[strlen(msg2)-1]=='\r')
00532         msg2[strlen(msg2)-1]=0;
00533     if(msg2[strlen(msg2)-1]=='\n')
00534         msg2[strlen(msg2)-1]=0;
00535     if(msg2[strlen(msg2)-1]=='\r')
00536         msg2[strlen(msg2)-1]=0;
00537     if(msg2[strlen(msg2)-1]=='\n')
00538         msg2[strlen(msg2)-1]=0;
00539 
00540     if(log_ssl_) {
00541         FILE* f=fopen("logs" FILE_SLASH "ssl.log","a");
00542         if(f) {
00543             char now[128];
00544             time_t n=time(NULL);
00545             strcpy(now,ctime(&n));
00546             now[26-1-1]=0;
00547             fprintf(f,"%s%s%s\n",now,": ",msg2);
00548             fclose(f);
00549         }
00550     }
00551 
00552     if(log_echo_ssl)
00553         printf("%s%s\n","OpenSSL ",msg2);
00554 
00555     logic_on_internal_event("@log@","ssl","","","",PRIVATE_EVENT_SEVERITY_CODE_INFORMATIONAL,msg2,"");
00556 
00557     delete[] msg2;
00558 }

Here is the call graph for this function:

char* ltoa long  value,
char *  buffer,
int  radix
 

ltoa() emulation for compiler which doesn't have it

Author:
VooDooMan
Version:
1
Date:
2004
Parameters:
value Value to convert to string
buffer Output string
radix *MUST* be 10
Returns:
Returns buffer
Bug:
radix MUST be 10!

Definition at line 171 of file dcc.cpp.

00172 {
00173     sprintf(buffer,"%ld",value);
00174     return buffer;
00175 }


Variable Documentation

bool log_bot_ = true
 

Set this to true if BOT log messages should be written to file.

Definition at line 105 of file log.cpp.

Referenced by init_echoes(), and log_bot().

bool log_botnet_ = true
 

Set this to true if BOTNET log messages should be written to file.

Definition at line 107 of file log.cpp.

Referenced by init_echoes(), and log_botnet().

bool log_botnet_debug_ = true
 

Set this to true if BOTNET debug log messages should be written to file.

Definition at line 108 of file log.cpp.

Referenced by init_echoes(), and log_botnet_debug().

bool log_broadcast_ = true
 

Set this to true if broadcasted messages from IRC operators should be written to file.

Definition at line 110 of file log.cpp.

Referenced by init_echoes().

bool log_debug_ = true
 

Set this to true if DEBUG log messages should be written to file.

Definition at line 102 of file log.cpp.

Referenced by init_echoes(), and log_debug().

bool log_echo_bot = true
 

Set this to true if BOT log messages should be echoed to stdout in console.

Definition at line 95 of file log.cpp.

Referenced by init_echoes(), and log_bot().

bool log_echo_botnet = true
 

Set this to true if BOTNET log messages should be echoed to stdout in console.

Definition at line 97 of file log.cpp.

Referenced by init_echoes(), and log_botnet().

bool log_echo_botnet_debug = true
 

Set this to true if BOTNET debug log messages should be echoed to stdout in console.

Definition at line 98 of file log.cpp.

Referenced by init_echoes(), and log_botnet_debug().

bool log_echo_broadcast = true
 

Set this to true if broadcasted messages from IRC operators should be echoed to stdout in console.

Definition at line 100 of file log.cpp.

Referenced by init_echoes().

bool log_echo_debug = true
 

Set this to true if DEBUG log messages should be echoed to stdout in console.

Definition at line 92 of file log.cpp.

Referenced by init_echoes(), and log_debug().

bool log_echo_identd = true
 

Set this to true if IDENTD log messages should be echoed to stdout in console.

Definition at line 96 of file log.cpp.

Referenced by init_echoes(), and log_identd().

bool log_echo_irc = true
 

Set this to true if IRC log messages should be echoed to stdout in console.

Definition at line 93 of file log.cpp.

Referenced by init_echoes(), and log_irc().

bool log_echo_socket = true
 

Set this to true if SOCKET log messages should be echoed to stdout in console.

Definition at line 94 of file log.cpp.

Referenced by init_echoes(), and log_socket().

bool log_echo_ssl = true
 

Set this to true if SSL debug log messages should be echoed to stdout in console.

Definition at line 99 of file log.cpp.

Referenced by init_echoes(), and log_ssl().

bool log_identd_ = true
 

Set this to true if IDENTD log messages should be written to file.

Definition at line 106 of file log.cpp.

Referenced by init_echoes(), and log_identd().

bool log_initialized = false
 

Was echoes/logs initialized?

Definition at line 112 of file log.cpp.

Referenced by init_echoes(), log_bot(), log_botnet(), log_botnet_debug(), log_broadcast(), log_channel(), log_debug(), log_done(), log_identd(), log_init(), log_irc(), log_socket(), and log_ssl().

bool log_irc_ = true
 

Set this to true if IRC log messages should be written to file.

Definition at line 103 of file log.cpp.

Referenced by init_echoes(), and log_irc().

bool log_socket_ = true
 

Set this to true if SOCKET log messages should be written to file.

Definition at line 104 of file log.cpp.

Referenced by init_echoes(), and log_socket().

bool log_ssl_ = true
 

Set this to true if SSL debug log messages should be written to file.

Definition at line 109 of file log.cpp.

Referenced by init_echoes(), and log_ssl().

FILE* pid = NULL
 

.pid file handle

Definition at line 114 of file log.cpp.

Referenced by log_free_locks(), and log_init().

int posix_lock_file = -1
 

.lock file handle (Unices only), or -1 for problems = should be ignored to close()

Definition at line 115 of file log.cpp.

Referenced by log_free_locks(), and log_init().


Generated on Sun Jul 10 04:55:16 2005 for VooDoo cIRCle by doxygen 1.4.3

Hosted by SourceForge.net Logo