X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Fchannel.c;h=edb0f6205dfee3ac896142aa931e0a6fef5c9f2c;hp=9ff4c1b5efe26d6a791ba0fe3b3e328b13171b04;hb=84706af7fec9243f84a3c11a3492f64b3af1cbe6;hpb=d81dab99fa28f21054fc7c5678cbd973b0ab5283 diff --git a/src/ngircd/channel.c b/src/ngircd/channel.c index 9ff4c1b5..edb0f620 100644 --- a/src/ngircd/channel.c +++ b/src/ngircd/channel.c @@ -17,12 +17,13 @@ #include "portab.h" -static char UNUSED id[] = "$Id: channel.c,v 1.50 2005/06/18 08:57:37 fw Exp $"; +static char UNUSED id[] = "$Id: channel.c,v 1.52 2005/07/28 16:23:55 fw Exp $"; #include "imp.h" #include #include #include +#include #include #include "defines.h" @@ -76,7 +77,7 @@ Channel_InitPredefined( void ) CHANNEL *chan; char *c; - int i; + unsigned int i; for( i = 0; i < Conf_Channel_Count; i++ ) { @@ -87,6 +88,7 @@ Channel_InitPredefined( void ) if( ! Channel_IsValidName( Conf_Channel[i].name )) { Log( LOG_ERR, "Can't create pre-defined channel: invalid name: \"%s\"!", Conf_Channel[i].name ); + array_free(&Conf_Channel[i].topic); continue; } @@ -95,6 +97,7 @@ Channel_InitPredefined( void ) if( chan ) { Log( LOG_INFO, "Can't create pre-defined channel \"%s\": name already in use.", Conf_Channel[i].name ); + array_free(&Conf_Channel[i].topic); continue; } @@ -103,7 +106,11 @@ Channel_InitPredefined( void ) if( chan ) { Channel_ModeAdd( chan, 'P' ); - Channel_SetTopic( chan, Conf_Channel[i].topic ); + if (!array_copy(&chan->topic, &Conf_Channel[i].topic)) { + Log( LOG_WARNING, "Could not set topic for new pre-defined channel: %s", + strerror(errno)); + } + array_free(&Conf_Channel[i].topic); c = Conf_Channel[i].modes; while( *c ) Channel_ModeAdd( chan, *c++ ); Log( LOG_INFO, "Created pre-defined channel \"%s\".", Conf_Channel[i].name ); @@ -124,6 +131,7 @@ Channel_Exit( void ) while( c ) { c_next = c->next; + array_free(&c->topic); free( c ); c = c_next; } @@ -621,18 +629,28 @@ Channel_IsMemberOf( CHANNEL *Chan, CLIENT *Client ) GLOBAL char * Channel_Topic( CHANNEL *Chan ) { + char *ret; assert( Chan != NULL ); - return Chan->topic; + ret = array_start(&Chan->topic); + return ret ? ret : ""; } /* Channel_Topic */ GLOBAL void Channel_SetTopic( CHANNEL *Chan, char *Topic ) { + size_t len; assert( Chan != NULL ); assert( Topic != NULL ); - - strlcpy( Chan->topic, Topic, sizeof( Chan->topic )); + + len = strlen(Topic); + if (len < array_bytes(&Chan->topic)) + array_free(&Chan->topic); + + if (!array_copyb(&Chan->topic, Topic, len)) + Log(LOG_WARNING, "could not set new Topic %s: %s", Topic, strerror(errno)); + + array_cat0(&Chan->topic); } /* Channel_SetTopic */ @@ -720,9 +738,9 @@ Channel_Create( char *Name ) c->hash = Hash( c->name ); c->next = My_Channels; My_Channels = c; - +#ifdef DEBUG Log( LOG_DEBUG, "Created new channel structure for \"%s\".", Name ); - +#endif return c; } /* Channel_Create */