Ticket #239: im_log.patch
File im_log.patch, 7.2 KB (added by , at 2007-05-17T22:27:03Z) |
---|
-
im_log.c
1 /********************************************************************\ 2 * BitlBee -- An IRC to other IM-networks gateway * 3 * * 4 * Copyright 2002-2007 Wilmer van der Gaast and others * 5 \********************************************************************/ 6 7 /* Log IM messages to a text file */ 8 9 /* 10 This program is free software; you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 2 of the License, or 13 (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License with 21 the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; 22 if not, write to the Free Software Foundation, Inc., 59 Temple Place, 23 Suite 330, Boston, MA 02111-1307 USA 24 */ 25 26 #define BITLBEE_CORE 27 #include <time.h> 28 #include "bitlbee.h" 29 #include "im_log.h" 30 31 static FILE* out = NULL; 32 33 static void open_log ( irc_t* irc ); 34 static void close_log ( void ); 35 36 static void handle_error ( irc_t* irc ) 37 { 38 irc_usermsg ( irc, "There was a problem opening the logfile. Disabling logging" ); 39 set_setstr ( &irc->set, "enable_logging", "false" ); 40 } 41 42 static void open_log ( irc_t* irc ) 43 { 44 char logfile[512]; 45 char *nick; 46 int ret; 47 48 nick = g_strdup( irc->nick ); 49 nick_lc( nick ); 50 51 ret = g_snprintf ( logfile, sizeof ( logfile ), "%s%s%s", global.conf->configdir, nick, ".log"); 52 if ( ret < 0 ) 53 { 54 handle_error ( irc ); 55 return; 56 } 57 58 out = fopen ( logfile, "a+" ); 59 60 if ( out == NULL ) 61 handle_error ( irc ); 62 } 63 64 static void close_log ( void ) 65 { 66 fclose ( out ); 67 out = NULL; 68 } 69 70 static void write_message ( const char* who, const char* msg ) 71 { 72 time_t now = time ( NULL ); 73 char* timestamp = asctime ( localtime ( &now ) ); 74 75 /* Because asctime adds a '\n' */ 76 timestamp[strlen ( timestamp ) - 1 ] = 0; 77 78 fprintf ( out, "%s %s %s\n", timestamp, who, msg ); 79 fflush ( out ); 80 } 81 82 void im_log_message (irc_t* irc, const char* who, const char* msg) 83 { 84 if ( set_getbool ( &irc->set, "enable_logging") ) 85 { 86 if ( ! out ) 87 open_log ( irc ); 88 89 if ( out ) 90 /* Because open_log could fail */ 91 write_message ( who, msg ); 92 } 93 else 94 { 95 if ( out ) 96 close_log (); 97 } 98 } 99 -
im_log.h
1 /********************************************************************\ 2 * BitlBee -- An IRC to other IM-networks gateway * 3 * * 4 * Copyright 2002-2007 Wilmer van der Gaast and others * 5 \********************************************************************/ 6 7 /* Log IM messages to a text file */ 8 9 /* 10 This program is free software; you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 2 of the License, or 13 (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License with 21 the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; 22 if not, write to the Free Software Foundation, Inc., 59 Temple Place, 23 Suite 330, Boston, MA 02111-1307 USA 24 */ 25 26 #ifndef _IM_LOG_H 27 #define _IM_LOG_H 28 29 void im_log_message (irc_t* irc, const char* nick, const char *message); 30 31 #endif -
Makefile
9 9 -include Makefile.settings 10 10 11 11 # Program variables 12 objects = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) unix.o user.o 13 headers = account.h bitlbee.h commands.h conf.h config.h crypting.h help.h ini.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h url.h user.h protocols/http_client.h protocols/md5.h protocols/nogaim.h protocols/proxy.h protocols/sha.h protocols/ssl_client.h 12 objects = account.o bitlbee.o conf.o crypting.o help.o ipc.o irc.o irc_commands.o log.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) unix.o user.o im_log.o 13 headers = account.h bitlbee.h commands.h conf.h config.h crypting.h help.h ini.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h url.h user.h protocols/http_client.h protocols/md5.h protocols/nogaim.h protocols/proxy.h protocols/sha.h protocols/ssl_client.h im_log.h 14 14 subdirs = lib protocols 15 15 16 16 # Expansion of variables -
bitlbee.h
132 132 #include "sock.h" 133 133 #include "misc.h" 134 134 #include "proxy.h" 135 #include "im_log.h" 135 136 136 137 typedef struct global { 137 138 /* In forked mode, child processes store the fd of the IPC socket here. */ -
irc.c
145 145 set_add( &irc->set, "strip_html", "true", NULL, irc ); 146 146 set_add( &irc->set, "to_char", ": ", set_eval_to_char, irc ); 147 147 set_add( &irc->set, "typing_notice", "false", set_eval_bool, irc ); 148 148 set_add ( &irc->set, "enable_logging", "false", set_eval_bool, irc ); 149 149 150 conf_loaddefaults( irc ); 150 151 151 152 return( irc ); -
protocols/nogaim.c
193 193 for( a = ic->irc->accounts; a; a = a->next ) 194 194 if( a->prpl == ic->acc->prpl && a->ic != ic ) 195 195 break; 196 196 197 im_log_message ( ic->irc, ic->acc->prpl->name, text); 198 197 199 /* If we found one, include the screenname in the message. */ 198 200 if( a ) 199 201 irc_usermsg( ic->irc, "%s(%s) - %s", ic->acc->prpl->name, ic->acc->user, text ); … … 650 652 tmp = *nl; 651 653 *nl = 0; 652 654 } 653 655 656 im_log_message ( irc, u->nick, msg ); 654 657 irc_msgfrom( irc, u->nick, msg ); 655 658 656 659 /* Move on. */ … … 665 668 msg += 425; 666 669 } 667 670 } 671 672 im_log_message ( irc, u->nick, msg ); 668 673 irc_msgfrom( irc, u->nick, msg ); 669 674 } 670 675 … … 725 730 { 726 731 struct im_connection *ic = c->ic; 727 732 user_t *u; 733 734 im_log_message ( ic->irc, who, msg ); 728 735 729 736 /* Gaim sends own messages through this too. IRC doesn't want this, so kill them */ 730 737 if( g_strcasecmp( who, ic->acc->user ) == 0 ) … … 945 952 buf = escape_html( msg ); 946 953 msg = buf; 947 954 } 948 955 956 im_log_message ( ic->irc, handle, msg ); 949 957 st = ic->acc->prpl->buddy_msg( ic, handle, msg, flags ); 950 958 g_free( buf ); 951 959