diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2006-01-18 23:17:59 +0100 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2006-01-18 23:17:59 +0100 | 
| commit | 4c266f2d79212e4e0ff4b9b33088685a2ec452e4 (patch) | |
| tree | 57312efb83e7f4eb1351215dec285d56dc7ebf99 | |
| parent | 1ea13be2cf335a471f85ea54d610fb91b7d14564 (diff) | |
| parent | c1826c6f72d1fe85e1c5decf5207601dac2c23e7 (diff) | |
Merged (and adapted) changes from main tree.
| -rw-r--r-- | bitlbee.c | 26 | ||||
| -rw-r--r-- | ipc.c | 3 | ||||
| -rw-r--r-- | irc.c | 14 | ||||
| -rw-r--r-- | irc.h | 4 | ||||
| -rw-r--r-- | irc_commands.c | 2 | ||||
| -rw-r--r-- | log.c | 112 | 
6 files changed, 89 insertions, 72 deletions
| @@ -169,7 +169,7 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit  	if( !irc_process( irc ) )  	{  		log_message( LOGLVL_INFO, "Destroying connection with fd %d.", irc->fd ); -		irc_free( irc ); +		irc_abort( irc );  		return FALSE;  	}  @@ -177,7 +177,7 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit  	if( irc->readbuffer && ( strlen( irc->readbuffer ) > 1024 ) )  	{  		log_message( LOGLVL_ERROR, "Maximum line length exceeded." ); -		irc_free( irc ); +		irc_abort( irc );  		return FALSE;  	} @@ -196,25 +196,25 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi  	size = strlen( irc->sendbuffer );  	st = write( irc->fd, irc->sendbuffer, size ); -	if( st <= 0 ) +	if( st == 0 || ( st < 0 && !sockerr_again() ) )  	{ -		if( sockerr_again() ) -		{ -			return TRUE; -		} -		else -		{ -			irc_free( irc ); -			return FALSE; -		} +		irc_free( irc ); +		return FALSE; +	} +	else if( st < 0 ) /* && sockerr_again() */ +	{ +		return TRUE;  	}  	if( st == size )  	{  		g_free( irc->sendbuffer );  		irc->sendbuffer = NULL; -		  		irc->w_watch_source_id = 0; +		 +		if( irc->status == USTATUS_SHUTDOWN ) +			irc_free( irc ); +		  		return( FALSE );  	}  	else @@ -124,7 +124,8 @@ static int ipc_child_cmd_kill( irc_t *irc, char **cmd )  		return 1;	/* It's not for us. */  	irc_write( irc, ":%s!%s@%s KILL %s :%s", irc->mynick, irc->mynick, irc->myhost, irc->nick, cmd[2] ); -	g_io_channel_close( irc->io_channel ); +	irc_abort( irc ); +	/* g_io_channel_close( irc->io_channel ); */  	return 0;  } @@ -150,6 +150,20 @@ irc_t *irc_new( int fd )  	return( irc );  } +void irc_abort( irc_t *irc ) +{ +	irc->status = USTATUS_SHUTDOWN; +	if( irc->sendbuffer ) +	{ +		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 ); +	} +	else +	{ +		irc_free( irc ); +	} +} +  static gboolean irc_free_userhash( gpointer key, gpointer value, gpointer data )  {  	g_free( key ); @@ -43,7 +43,8 @@ typedef enum  	USTATUS_OFFLINE,  	USTATUS_AUTHORIZED,  	USTATUS_LOGGED_IN, -	USTATUS_IDENTIFIED +	USTATUS_IDENTIFIED, +	USTATUS_SHUTDOWN  } irc_status_t;  typedef struct channel @@ -103,6 +104,7 @@ typedef struct irc  extern GSList *irc_connection_list;  irc_t *irc_new( int fd ); +void irc_abort( irc_t *irc );  void irc_free( irc_t *irc );  int irc_exec( irc_t *irc, char **cmd ); diff --git a/irc_commands.c b/irc_commands.c index 2e225702..152df767 100644 --- a/irc_commands.c +++ b/irc_commands.c @@ -81,7 +81,7 @@ static int irc_cmd_nick( irc_t *irc, char **cmd )  static int irc_cmd_quit( irc_t *irc, char **cmd )  {  	irc_write( irc, "ERROR :%s%s", cmd[1]?"Quit: ":"", cmd[1]?cmd[1]:"Client Quit" ); -	g_io_channel_close( irc->io_channel ); +	/* g_io_channel_close( irc->io_channel ); */  	return( 0 );  } @@ -37,11 +37,11 @@ static void log_console(int level, char *logmessage);  void log_init(void) {  	openlog("bitlbee", LOG_PID, LOG_DAEMON);	 -	logoutput.informational=&log_null; -	logoutput.warning=&log_null; -	logoutput.error=&log_null; +	logoutput.informational = &log_null; +	logoutput.warning = &log_null; +	logoutput.error = &log_null;  #ifdef DEBUG -	logoutput.debug=&log_null; +	logoutput.debug = &log_null;  #endif  	return; @@ -50,46 +50,46 @@ void log_init(void) {  void log_link(int level, int output) {  	/* I know it's ugly, but it works and I didn't feel like messing with pointer to function pointers */ -	if(level==LOGLVL_INFO) { -		if(output==LOGOUTPUT_NULL) -			logoutput.informational=&log_null;	 -		else if(output==LOGOUTPUT_IRC) -			logoutput.informational=&log_irc;	 -		else if(output==LOGOUTPUT_SYSLOG) -			logoutput.informational=&log_syslog;	 -		else if(output==LOGOUTPUT_CONSOLE)  -			logoutput.informational=&log_console;	 +	if(level == LOGLVL_INFO) { +		if(output == LOGOUTPUT_NULL) +			logoutput.informational = &log_null;	 +		else if(output == LOGOUTPUT_IRC) +			logoutput.informational = &log_irc;	 +		else if(output == LOGOUTPUT_SYSLOG) +			logoutput.informational = &log_syslog;	 +		else if(output == LOGOUTPUT_CONSOLE)  +			logoutput.informational = &log_console;	  	} -	else if(level==LOGLVL_WARNING) { -		if(output==LOGOUTPUT_NULL) -			logoutput.warning=&log_null; -		else if(output==LOGOUTPUT_IRC) -			logoutput.warning=&log_irc; -		else if(output==LOGOUTPUT_SYSLOG) -			logoutput.warning=&log_syslog; -		else if(output==LOGOUTPUT_CONSOLE) -			logoutput.warning=&log_console; +	else if(level == LOGLVL_WARNING) { +		if(output == LOGOUTPUT_NULL) +			logoutput.warning = &log_null; +		else if(output == LOGOUTPUT_IRC) +			logoutput.warning = &log_irc; +		else if(output == LOGOUTPUT_SYSLOG) +			logoutput.warning = &log_syslog; +		else if(output == LOGOUTPUT_CONSOLE) +			logoutput.warning = &log_console;  	} -	else if(level==LOGLVL_ERROR) { -		if(output==LOGOUTPUT_NULL) -			logoutput.error=&log_null; -		else if(output==LOGOUTPUT_IRC) -			logoutput.error=&log_irc; -		else if(output==LOGOUTPUT_SYSLOG) -			logoutput.error=&log_syslog; -		else if(output==LOGOUTPUT_CONSOLE) -			logoutput.error=&log_console; +	else if(level == LOGLVL_ERROR) { +		if(output == LOGOUTPUT_NULL) +			logoutput.error = &log_null; +		else if(output == LOGOUTPUT_IRC) +			logoutput.error = &log_irc; +		else if(output == LOGOUTPUT_SYSLOG) +			logoutput.error = &log_syslog; +		else if(output == LOGOUTPUT_CONSOLE) +			logoutput.error = &log_console;  	}  #ifdef DEBUG -	else if(level==LOGLVL_DEBUG) { -		if(output==LOGOUTPUT_NULL) -			logoutput.debug=&log_null; -		else if(output==LOGOUTPUT_IRC) -			logoutput.debug=&log_irc; -		else if(output==LOGOUTPUT_SYSLOG) -			logoutput.debug=&log_syslog; -		else if(output==LOGOUTPUT_CONSOLE) -			logoutput.debug=&log_console; +	else if(level == LOGLVL_DEBUG) { +		if(output == LOGOUTPUT_NULL) +			logoutput.debug = &log_null; +		else if(output == LOGOUTPUT_IRC) +			logoutput.debug = &log_irc; +		else if(output == LOGOUTPUT_SYSLOG) +			logoutput.debug = &log_syslog; +		else if(output == LOGOUTPUT_CONSOLE) +			logoutput.debug = &log_console;  	}  #endif  	return;	 @@ -105,14 +105,14 @@ void log_message(int level, char *message, ... ) {  	msgstring = g_strdup_vprintf(message, ap);  	va_end(ap); -	if(level==LOGLVL_INFO) +	if(level == LOGLVL_INFO)  		(*(logoutput.informational))(level, msgstring); -	if(level==LOGLVL_WARNING)  +	if(level == LOGLVL_WARNING)   		(*(logoutput.warning))(level, msgstring); -	if(level==LOGLVL_ERROR) +	if(level == LOGLVL_ERROR)  		(*(logoutput.error))(level, msgstring);  #ifdef DEBUG -	if(level==LOGLVL_DEBUG) +	if(level == LOGLVL_DEBUG)  		(*(logoutput.debug))(level, msgstring);  #endif @@ -132,14 +132,14 @@ static void log_null(int level, char *message) {  }  static void log_irc(int level, char *message) { -	if(level==LOGLVL_ERROR) +	if(level == LOGLVL_ERROR)  		irc_write_all(1, "ERROR :Error: %s", message); -	if(level==LOGLVL_WARNING) +	if(level == LOGLVL_WARNING)  		irc_write_all(0, "ERROR :Warning: %s", message); -	if(level==LOGLVL_INFO) +	if(level == LOGLVL_INFO)  		irc_write_all(0, "ERROR :Informational: %s", message);	  #ifdef DEBUG -	if(level==LOGLVL_DEBUG) +	if(level == LOGLVL_DEBUG)  		irc_write_all(0, "ERROR :Debug: %s", message);	  #endif	 @@ -147,28 +147,28 @@ static void log_irc(int level, char *message) {  }  static void log_syslog(int level, char *message) { -	if(level==LOGLVL_ERROR) +	if(level == LOGLVL_ERROR)  		syslog(LOG_ERR, "%s", message); -	if(level==LOGLVL_WARNING) +	if(level == LOGLVL_WARNING)  		syslog(LOG_WARNING, "%s", message); -	if(level==LOGLVL_INFO) +	if(level == LOGLVL_INFO)  		syslog(LOG_INFO, "%s", message);  #ifdef DEBUG -	if(level==LOGLVL_DEBUG) +	if(level == LOGLVL_DEBUG)  		syslog(LOG_DEBUG, "%s", message);  #endif  	return;  }  static void log_console(int level, char *message) { -	if(level==LOGLVL_ERROR) +	if(level == LOGLVL_ERROR)  		fprintf(stderr, "Error: %s\n", message); -	if(level==LOGLVL_WARNING) +	if(level == LOGLVL_WARNING)  		fprintf(stderr, "Warning: %s\n", message); -	if(level==LOGLVL_INFO) +	if(level == LOGLVL_INFO)  		fprintf(stdout, "Informational: %s\n", message);  #ifdef DEBUG -	if(level==LOGLVL_DEBUG) +	if(level == LOGLVL_DEBUG)  		fprintf(stdout, "Debug: %s\n", message);  #endif  	return; | 
