diff options
| -rw-r--r-- | bitlbee.c | 11 | ||||
| -rw-r--r-- | irc.c | 38 | ||||
| -rw-r--r-- | irc.h | 2 | 
3 files changed, 40 insertions, 11 deletions
| @@ -162,14 +162,14 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit  	if( condition & G_IO_ERR || condition & G_IO_HUP )  	{ -		irc_free( irc ); +		irc_abort( irc, 1, "Read error" );  		return FALSE;  	}  	st = read( irc->fd, line, sizeof( line ) - 1 );  	if( st == 0 )  	{ -		irc_free( irc ); +		irc_abort( irc, 1, "Connection reset by peer" );  		return FALSE;  	}  	else if( st < 0 ) @@ -180,7 +180,7 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit  		}  		else  		{ -			irc_free( irc ); +			irc_abort( irc, 1, "Read error: %s", strerror( errno ) );  			return FALSE;  		}  	} @@ -206,8 +206,7 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit  	/* Very naughty, go read the RFCs! >:) */  	if( irc->readbuffer && ( strlen( irc->readbuffer ) > 1024 ) )  	{ -		log_message( LOGLVL_ERROR, "Maximum line length exceeded." ); -		irc_abort( irc ); +		irc_abort( irc, 0, "Maximum line length exceeded" );  		return FALSE;  	} @@ -228,7 +227,7 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi  	if( st == 0 || ( st < 0 && !sockerr_again() ) )  	{ -		irc_free( irc ); +		irc_abort( irc, 1, "Write error: %s", strerror( errno ) );  		return FALSE;  	}  	else if( st < 0 ) /* && sockerr_again() */ @@ -150,11 +150,42 @@ irc_t *irc_new( int fd )  	return( irc );  } -void irc_abort( irc_t *irc ) +void irc_abort( irc_t *irc, int immed, char *format, ... )  { +	va_list params; +	 +	if( format != NULL ) +	{ +		char *reason; +		 +		va_start( params, format ); +		reason = g_strdup_printf( format, params ); +		va_end( params ); +		 +		if( !immed ) +			irc_write( irc, "ERROR :Closing link: %s", reason ); +		 +		ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n", +	                           irc->nick, irc->host, reason" ); +	     	 +		g_free( reason ); +	} +	else +	{ +		if( !immed ) +			irc_write( irc, "ERROR :Closing link" ); +		 +		ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n", +	        	           irc->nick, irc->host, "No reason given" ); +	} +	  	irc->status = USTATUS_SHUTDOWN; -	if( irc->sendbuffer ) +	if( irc->sendbuffer && !immed )  	{ +		/* We won't read from this socket anymore. Instead, we'll connect a timer +		   to it that should shut down the connection in a second, just in case +		   bitlbee_.._write doesn't do it first. */ +		  		g_source_remove( irc->r_watch_source_id );  		irc->r_watch_source_id = g_timeout_add_full( G_PRIORITY_HIGH, 1000, (GSourceFunc) irc_free, irc, NULL );  	} @@ -1622,8 +1653,7 @@ static gboolean irc_userping( gpointer _irc )  	if( rv > 0 )  	{ -		irc_write( irc, "ERROR :Closing Link: Ping Timeout: %d seconds", rv ); -		irc_free( irc ); +		irc_abort( irc, "ERROR :Closing Link: Ping Timeout: %d seconds", rv );  		return FALSE;  	} @@ -104,7 +104,7 @@ typedef struct irc  extern GSList *irc_connection_list;  irc_t *irc_new( int fd ); -void irc_abort( irc_t *irc ); +void irc_abort( irc_t *irc, int immed, char *format, ... );  void irc_free( irc_t *irc );  int irc_exec( irc_t *irc, char **cmd ); | 
