topic no longer limited to 127 chars (now only limited by protocol)

This commit is contained in:
Florian Westphal 2005-07-28 16:23:55 +00:00
parent 46a191caf6
commit 84706af7fe
6 changed files with 45 additions and 24 deletions

View File

@ -17,12 +17,13 @@
#include "portab.h" #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 "imp.h"
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <strings.h> #include <strings.h>
#include "defines.h" #include "defines.h"
@ -87,6 +88,7 @@ Channel_InitPredefined( void )
if( ! Channel_IsValidName( Conf_Channel[i].name )) if( ! Channel_IsValidName( Conf_Channel[i].name ))
{ {
Log( LOG_ERR, "Can't create pre-defined channel: invalid name: \"%s\"!", 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; continue;
} }
@ -95,6 +97,7 @@ Channel_InitPredefined( void )
if( chan ) if( chan )
{ {
Log( LOG_INFO, "Can't create pre-defined channel \"%s\": name already in use.", Conf_Channel[i].name ); 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; continue;
} }
@ -103,7 +106,11 @@ Channel_InitPredefined( void )
if( chan ) if( chan )
{ {
Channel_ModeAdd( chan, 'P' ); 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; c = Conf_Channel[i].modes;
while( *c ) Channel_ModeAdd( chan, *c++ ); while( *c ) Channel_ModeAdd( chan, *c++ );
Log( LOG_INFO, "Created pre-defined channel \"%s\".", Conf_Channel[i].name ); Log( LOG_INFO, "Created pre-defined channel \"%s\".", Conf_Channel[i].name );
@ -124,6 +131,7 @@ Channel_Exit( void )
while( c ) while( c )
{ {
c_next = c->next; c_next = c->next;
array_free(&c->topic);
free( c ); free( c );
c = c_next; c = c_next;
} }
@ -621,18 +629,28 @@ Channel_IsMemberOf( CHANNEL *Chan, CLIENT *Client )
GLOBAL char * GLOBAL char *
Channel_Topic( CHANNEL *Chan ) Channel_Topic( CHANNEL *Chan )
{ {
char *ret;
assert( Chan != NULL ); assert( Chan != NULL );
return Chan->topic; ret = array_start(&Chan->topic);
return ret ? ret : "";
} /* Channel_Topic */ } /* Channel_Topic */
GLOBAL void GLOBAL void
Channel_SetTopic( CHANNEL *Chan, char *Topic ) Channel_SetTopic( CHANNEL *Chan, char *Topic )
{ {
size_t len;
assert( Chan != NULL ); assert( Chan != NULL );
assert( Topic != 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 */ } /* Channel_SetTopic */
@ -720,9 +738,9 @@ Channel_Create( char *Name )
c->hash = Hash( c->name ); c->hash = Hash( c->name );
c->next = My_Channels; c->next = My_Channels;
My_Channels = c; My_Channels = c;
#ifdef DEBUG
Log( LOG_DEBUG, "Created new channel structure for \"%s\".", Name ); Log( LOG_DEBUG, "Created new channel structure for \"%s\".", Name );
#endif
return c; return c;
} /* Channel_Create */ } /* Channel_Create */

View File

@ -8,7 +8,7 @@
* (at your option) any later version. * (at your option) any later version.
* Please read the file COPYING, README and AUTHORS for more information. * 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) * Channel management (header)
*/ */
@ -21,6 +21,7 @@
#if defined(__channel_c__) | defined(S_SPLINT_S) #if defined(__channel_c__) | defined(S_SPLINT_S)
#include "defines.h" #include "defines.h"
#include "array.h"
typedef struct _CHANNEL typedef struct _CHANNEL
{ {
@ -28,7 +29,7 @@ typedef struct _CHANNEL
char name[CHANNEL_NAME_LEN]; /* Name of the channel */ char name[CHANNEL_NAME_LEN]; /* Name of the channel */
UINT32 hash; /* Hash of the (lowecase!) name */ UINT32 hash; /* Hash of the (lowecase!) name */
char modes[CHANNEL_MODE_LEN]; /* Channel modes */ 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" ) */ char key[CLIENT_PASS_LEN]; /* Channel key ("password", mode "k" ) */
long maxusers; /* Maximum number of members (mode "l") */ long maxusers; /* Maximum number of members (mode "l") */
} CHANNEL; } CHANNEL;

View File

@ -14,7 +14,7 @@
#include "portab.h" #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 "imp.h"
#include <assert.h> #include <assert.h>
@ -98,6 +98,7 @@ Conf_Test( void )
struct passwd *pwd; struct passwd *pwd;
struct group *grp; struct group *grp;
unsigned int i; unsigned int i;
char *topic;
Use_Log = false; Use_Log = false;
Set_Defaults( true ); Set_Defaults( true );
@ -187,7 +188,8 @@ Conf_Test( void )
puts( "[CHANNEL]" ); puts( "[CHANNEL]" );
printf( " Name = %s\n", Conf_Channel[i].name ); printf( " Name = %s\n", Conf_Channel[i].name );
printf( " Modes = %s\n", Conf_Channel[i].modes ); 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( "" ); puts( "" );
} }
@ -508,15 +510,14 @@ Read_Config( void )
else New_Server_Idx = i; else New_Server_Idx = i;
continue; continue;
} }
if( strcasecmp( section, "[CHANNEL]" ) == 0 ) if( strcasecmp( section, "[CHANNEL]" ) == 0 ) {
{ if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) {
if( Conf_Channel_Count + 1 > MAX_DEFCHANNELS ) Config_Error( LOG_ERR, "Too many pre-defined channels configured." ); Config_Error( LOG_ERR, "Too many pre-defined channels configured." );
else } else {
{
/* Initialize new channel structure */ /* Initialize new channel structure */
strcpy( Conf_Channel[Conf_Channel_Count].name, "" ); strcpy( Conf_Channel[Conf_Channel_Count].name, "" );
strcpy( Conf_Channel[Conf_Channel_Count].modes, "" ); 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++; Conf_Channel_Count++;
} }
continue; continue;
@ -934,7 +935,7 @@ Handle_CHANNEL( int Line, char *Var, char *Arg )
if( strcasecmp( Var, "Topic" ) == 0 ) if( strcasecmp( Var, "Topic" ) == 0 )
{ {
/* Initial topic */ /* 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 ); Config_Error_TooLong( Line, Var );
return; return;

View File

@ -8,7 +8,7 @@
* (at your option) any later version. * (at your option) any later version.
* Please read the file COPYING, README and AUTHORS for more information. * 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) * Configuration management (header)
*/ */
@ -20,6 +20,7 @@
#include <time.h> #include <time.h>
#include "defines.h" #include "defines.h"
#include "array.h"
#include "portab.h" #include "portab.h"
typedef struct _Conf_Oper typedef struct _Conf_Oper
@ -48,7 +49,7 @@ typedef struct _Conf_Channel
{ {
char name[CHANNEL_NAME_LEN]; /* Name of the channel */ char name[CHANNEL_NAME_LEN]; /* Name of the channel */
char modes[CHANNEL_MODE_LEN]; /* Initial channel modes */ char modes[CHANNEL_MODE_LEN]; /* Initial channel modes */
char topic[CHANNEL_TOPIC_LEN]; /* Initial topic */ array topic; /* Initial topic */
} CONF_CHANNEL; } CONF_CHANNEL;

View File

@ -8,7 +8,7 @@
* (at your option) any later version. * (at your option) any later version.
* Please read the file COPYING, README and AUTHORS for more information. * 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 #define CHANNEL_NAME_LEN 51 /* Max. length of a channel name, see
RFC 2812 section 1.3 */ RFC 2812 section 1.3 */
#define CHANNEL_MODE_LEN 9 /* Max. length of channel modes */ #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 #define COMMAND_LEN 513 /* Max. IRC command length, see. RFC
2812 section 3.2 */ 2812 section 3.2 */

View File

@ -14,7 +14,7 @@
#include "portab.h" #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 "imp.h"
#include <assert.h> #include <assert.h>
@ -542,7 +542,8 @@ Hello_User( CLIENT *Client )
#endif #endif
/* Features */ /* 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 ); Client_SetType( Client, CLIENT_USER );