]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/channel.c
topic no longer limited to 127 chars (now only limited by protocol)
[ngircd-alex.git] / src / ngircd / channel.c
index f92f20dbeb193e2be1726f163487ab8ccd2241e4..edb0f6205dfee3ac896142aa931e0a6fef5c9f2c 100644 (file)
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: channel.c,v 1.47 2005/04/27 07:34:25 alex Exp $";
+static char UNUSED id[] = "$Id: channel.c,v 1.52 2005/07/28 16:23:55 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 #include <strings.h>
 
 #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;
        }
@@ -248,6 +256,8 @@ Channel_Quit( CLIENT *Client, char *Reason )
        assert( Client != NULL );
        assert( Reason != NULL );
 
+       IRC_WriteStrRelatedPrefix( Client, Client, false, "QUIT :%s", Reason );
+
        c = My_Channels;
        while( c )
        {
@@ -619,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 */
 
 
@@ -718,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 */
 
@@ -807,7 +827,6 @@ Remove_Client( int Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, char *Re
                        /* QUIT: andere Server wurden bereits informiert, vgl. Client_Destroy();
                         * hier also "nur" noch alle User in betroffenen Channeln infomieren */
                        assert( InformServer == false );
-                       IRC_WriteStrChannelPrefix( Origin, c, Origin, false, "QUIT :%s", Reason );
                        Log( LOG_DEBUG, "User \"%s\" left channel \"%s\" (%s).", Client_Mask( Client ), c->name, Reason );
                        break;
                case REMOVE_KICK: