From: Florian Westphal Date: Thu, 28 Jul 2005 16:23:55 +0000 (+0000) Subject: topic no longer limited to 127 chars (now only limited by protocol) X-Git-Tag: rel-0-10-0-pre1~133 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd.git;a=commitdiff_plain;h=84706af7fec9243f84a3c11a3492f64b3af1cbe6 topic no longer limited to 127 chars (now only limited by protocol) --- diff --git a/src/ngircd/channel.c b/src/ngircd/channel.c index aaf38d1b..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.51 2005/07/11 14:11:35 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" @@ -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 */ diff --git a/src/ngircd/channel.h b/src/ngircd/channel.h index 1bc185a9..493161b0 100644 --- a/src/ngircd/channel.h +++ b/src/ngircd/channel.h @@ -8,7 +8,7 @@ * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. * - * $Id: channel.h,v 1.27 2005/03/19 18:43:48 fw Exp $ + * $Id: channel.h,v 1.28 2005/07/28 16:23:55 fw Exp $ * * Channel management (header) */ @@ -21,6 +21,7 @@ #if defined(__channel_c__) | defined(S_SPLINT_S) #include "defines.h" +#include "array.h" typedef struct _CHANNEL { @@ -28,7 +29,7 @@ typedef struct _CHANNEL char name[CHANNEL_NAME_LEN]; /* Name of the channel */ UINT32 hash; /* Hash of the (lowecase!) name */ char modes[CHANNEL_MODE_LEN]; /* Channel modes */ - char topic[CHANNEL_TOPIC_LEN]; /* Topic of the channel */ + array topic; /* Topic of the channel */ char key[CLIENT_PASS_LEN]; /* Channel key ("password", mode "k" ) */ long maxusers; /* Maximum number of members (mode "l") */ } CHANNEL; diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c index a10d1be0..0764d2c7 100644 --- a/src/ngircd/conf.c +++ b/src/ngircd/conf.c @@ -14,7 +14,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: conf.c,v 1.80 2005/07/17 18:58:04 fw Exp $"; +static char UNUSED id[] = "$Id: conf.c,v 1.81 2005/07/28 16:23:55 fw Exp $"; #include "imp.h" #include @@ -98,6 +98,7 @@ Conf_Test( void ) struct passwd *pwd; struct group *grp; unsigned int i; + char *topic; Use_Log = false; Set_Defaults( true ); @@ -187,7 +188,8 @@ Conf_Test( void ) puts( "[CHANNEL]" ); printf( " Name = %s\n", Conf_Channel[i].name ); printf( " Modes = %s\n", Conf_Channel[i].modes ); - printf( " Topic = %s\n", Conf_Channel[i].topic ); + topic = (char*)array_start(&Conf_Channel[i].topic); + printf( " Topic = %s\n", topic ? topic : ""); puts( "" ); } @@ -508,15 +510,14 @@ Read_Config( void ) else New_Server_Idx = i; continue; } - if( strcasecmp( section, "[CHANNEL]" ) == 0 ) - { - if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." ); - else - { + if( strcasecmp( section, "[CHANNEL]" ) == 0 ) { + if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) { + Config_Error( LOG_ERR, "Too many pre-defined channels configured." ); + } else { /* Initialize new channel structure */ strcpy( Conf_Channel[Conf_Channel_Count].name, "" ); strcpy( Conf_Channel[Conf_Channel_Count].modes, "" ); - strcpy( Conf_Channel[Conf_Channel_Count].topic, "" ); + array_free(&Conf_Channel[Conf_Channel_Count].topic); Conf_Channel_Count++; } continue; @@ -934,7 +935,7 @@ Handle_CHANNEL( int Line, char *Var, char *Arg ) if( strcasecmp( Var, "Topic" ) == 0 ) { /* Initial topic */ - if( strlcpy( Conf_Channel[Conf_Channel_Count - 1].topic, Arg, sizeof( Conf_Channel[Conf_Channel_Count - 1].topic )) >= sizeof( Conf_Channel[Conf_Channel_Count - 1].topic )) + if (!array_copys( &Conf_Channel[Conf_Channel_Count - 1].topic, Arg)) Config_Error_TooLong( Line, Var ); return; diff --git a/src/ngircd/conf.h b/src/ngircd/conf.h index a97526c6..e312ccca 100644 --- a/src/ngircd/conf.h +++ b/src/ngircd/conf.h @@ -8,7 +8,7 @@ * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. * - * $Id: conf.h,v 1.35 2005/07/11 14:11:35 fw Exp $ + * $Id: conf.h,v 1.36 2005/07/28 16:23:55 fw Exp $ * * Configuration management (header) */ @@ -20,6 +20,7 @@ #include #include "defines.h" +#include "array.h" #include "portab.h" typedef struct _Conf_Oper @@ -48,7 +49,7 @@ typedef struct _Conf_Channel { char name[CHANNEL_NAME_LEN]; /* Name of the channel */ char modes[CHANNEL_MODE_LEN]; /* Initial channel modes */ - char topic[CHANNEL_TOPIC_LEN]; /* Initial topic */ + array topic; /* Initial topic */ } CONF_CHANNEL; diff --git a/src/ngircd/defines.h b/src/ngircd/defines.h index 8feb5b86..70800c3d 100644 --- a/src/ngircd/defines.h +++ b/src/ngircd/defines.h @@ -8,7 +8,7 @@ * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. * - * $Id: defines.h,v 1.55 2005/07/08 16:18:39 alex Exp $ + * $Id: defines.h,v 1.56 2005/07/28 16:23:55 fw Exp $ */ @@ -62,7 +62,6 @@ #define CHANNEL_NAME_LEN 51 /* Max. length of a channel name, see RFC 2812 section 1.3 */ #define CHANNEL_MODE_LEN 9 /* Max. length of channel modes */ -#define CHANNEL_TOPIC_LEN 128 /* Max. length of a channel topic */ #define COMMAND_LEN 513 /* Max. IRC command length, see. RFC 2812 section 3.2 */ diff --git a/src/ngircd/irc-login.c b/src/ngircd/irc-login.c index db04a9c3..603d1167 100644 --- a/src/ngircd/irc-login.c +++ b/src/ngircd/irc-login.c @@ -14,7 +14,7 @@ #include "portab.h" -static char UNUSED id[] = "$Id: irc-login.c,v 1.44 2005/06/04 12:32:09 fw Exp $"; +static char UNUSED id[] = "$Id: irc-login.c,v 1.45 2005/07/28 16:23:55 fw Exp $"; #include "imp.h" #include @@ -542,7 +542,8 @@ Hello_User( CLIENT *Client ) #endif /* Features */ - if( ! IRC_WriteStrClient( Client, RPL_ISUPPORT_MSG, Client_ID( Client ), CLIENT_NICK_LEN - 1, CHANNEL_TOPIC_LEN - 1, CLIENT_AWAY_LEN - 1, Conf_MaxJoins )) return DISCONNECTED; + if( ! IRC_WriteStrClient( Client, RPL_ISUPPORT_MSG, Client_ID( Client ), CLIENT_NICK_LEN - 1, + COMMAND_LEN - 23, CLIENT_AWAY_LEN - 1, Conf_MaxJoins )) return DISCONNECTED; Client_SetType( Client, CLIENT_USER );