2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2009 Alexander Barton (alex@barton.de)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
29 #include "conn-func.h"
36 #include "irc-write.h"
52 static CHANNEL *My_Channels;
53 static CL2CHAN *My_Cl2Chan;
56 static CL2CHAN *Get_Cl2Chan PARAMS(( CHANNEL *Chan, CLIENT *Client ));
57 static CL2CHAN *Add_Client PARAMS(( CHANNEL *Chan, CLIENT *Client ));
58 static bool Remove_Client PARAMS(( int Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, const char *Reason, bool InformServer ));
59 static CL2CHAN *Get_First_Cl2Chan PARAMS(( CLIENT *Client, CHANNEL *Chan ));
60 static CL2CHAN *Get_Next_Cl2Chan PARAMS(( CL2CHAN *Start, CLIENT *Client, CHANNEL *Chan ));
61 static void Delete_Channel PARAMS(( CHANNEL *Chan ));
62 static void Free_Channel PARAMS(( CHANNEL *Chan ));
63 static void Set_KeyFile PARAMS((CHANNEL *Chan, const char *KeyFile));
74 sc = Channel_Create("&SERVER");
76 Channel_SetModes(sc, "mnPt");
77 Channel_SetTopic(sc, Client_ThisServer(), "Server Messages");
82 GLOBAL struct list_head *
83 Channel_GetListBans(CHANNEL *c)
90 GLOBAL struct list_head *
91 Channel_GetListInvites(CHANNEL *c)
94 return &c->list_invites;
99 Channel_InitPredefined( void )
101 /* Generate predefined persistent channels */
104 const struct Conf_Channel *conf_chan;
106 size_t i, channel_count = array_length(&Conf_Channels, sizeof(*conf_chan));
108 conf_chan = array_start(&Conf_Channels);
110 assert(channel_count == 0 || conf_chan != NULL);
112 for (i = 0; i < channel_count; i++, conf_chan++) {
113 if (!conf_chan->name[0] || !Channel_IsValidName(conf_chan->name)) {
114 Log(LOG_ERR, "Can't create pre-defined channel: invalid name: \"%s\"",
119 new_chan = Channel_Search(conf_chan->name);
122 "Can't create pre-defined channel \"%s\": name already in use.",
124 Set_KeyFile(new_chan, conf_chan->keyfile);
128 new_chan = Channel_Create(conf_chan->name);
130 Log(LOG_ERR, "Can't create pre-defined channel \"%s\"",
134 Log(LOG_INFO, "Created pre-defined channel \"%s\"",
137 Channel_ModeAdd(new_chan, 'P');
139 if (conf_chan->topic[0])
140 Channel_SetTopic(new_chan, NULL, conf_chan->topic);
142 c = conf_chan->modes;
144 Channel_ModeAdd(new_chan, *c++);
146 Channel_SetKey(new_chan, conf_chan->key);
147 Channel_SetMaxUsers(new_chan, conf_chan->maxusers);
148 Set_KeyFile(new_chan, conf_chan->keyfile);
151 array_free(&Conf_Channels);
152 } /* Channel_InitPredefined */
156 Free_Channel(CHANNEL *chan)
158 array_free(&chan->topic);
159 array_free(&chan->keyfile);
160 Lists_Free(&chan->list_bans);
161 Lists_Free(&chan->list_invites);
171 CL2CHAN *cl2chan, *cl2chan_next;
173 /* free struct Channel */
181 /* Free Channel allocation table */
182 cl2chan = My_Cl2Chan;
184 cl2chan_next = cl2chan->next;
186 cl2chan = cl2chan_next;
193 * This function lets a client join a channel. First, the function
194 * checks that the specified channel name is valid and that the client
195 * isn't already a member. If the specified channel doesn't exist,
196 * a new channel is created. Client is added to channel by function
200 Channel_Join( CLIENT *Client, const char *Name )
204 assert(Client != NULL);
205 assert(Name != NULL);
207 /* Check that the channel name is valid */
208 if (! Channel_IsValidName(Name)) {
209 IRC_WriteStrClient(Client, ERR_NOSUCHCHANNEL_MSG,
210 Client_ID(Client), Name);
214 chan = Channel_Search(Name);
216 /* Check if the client is already in the channel */
217 if (Get_Cl2Chan(chan, Client))
220 /* If the specified channel does not exist, the channel
222 chan = Channel_Create(Name);
227 /* Add user to Channel */
228 if (! Add_Client(chan, Client))
236 * Part client from channel.
237 * This function lets a client part from a channel. First, the function checks
238 * if the channel exists and the client is a member of it and sends out
239 * appropriate error messages if not. The real work is done by the function
243 Channel_Part(CLIENT * Client, CLIENT * Origin, const char *Name, const char *Reason)
247 assert(Client != NULL);
248 assert(Name != NULL);
249 assert(Reason != NULL);
251 /* Check that specified channel exists */
252 chan = Channel_Search(Name);
254 IRC_WriteStrClient(Client, ERR_NOSUCHCHANNEL_MSG,
255 Client_ID(Client), Name);
259 /* Check that the client is in the channel */
260 if (!Get_Cl2Chan(chan, Client)) {
261 IRC_WriteStrClient(Client, ERR_NOTONCHANNEL_MSG,
262 Client_ID(Client), Name);
266 /* Part client from channel */
267 if (!Remove_Client(REMOVE_PART, chan, Client, Origin, Reason, true))
275 * Kick user from Channel
278 Channel_Kick(CLIENT *Peer, CLIENT *Target, CLIENT *Origin, const char *Name,
283 assert(Peer != NULL);
284 assert(Target != NULL);
285 assert(Origin != NULL);
286 assert(Name != NULL);
287 assert(Reason != NULL);
289 /* Check that channel exists */
290 chan = Channel_Search( Name );
293 IRC_WriteStrClient( Origin, ERR_NOSUCHCHANNEL_MSG, Client_ID( Origin ), Name );
297 if (Client_Type(Peer) != CLIENT_SERVER &&
298 Client_Type(Origin) != CLIENT_SERVICE) {
299 /* Check that user is on the specified channel */
300 if (!Channel_IsMemberOf(chan, Origin)) {
301 IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG,
302 Client_ID(Origin), Name);
306 /* Check if user has operator status */
307 if (!strchr(Channel_UserModes(chan, Origin), 'o')) {
308 IRC_WriteStrClient(Origin, ERR_CHANOPRIVSNEEDED_MSG,
309 Client_ID(Origin), Name);
314 /* Check that the client to be kicked is on the specified channel */
315 if (!Channel_IsMemberOf(chan, Target)) {
316 IRC_WriteStrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
317 Client_ID(Origin), Client_ID(Target), Name );
321 /* Kick Client from channel */
322 Remove_Client( REMOVE_KICK, chan, Target, Origin, Reason, true);
327 Channel_Quit( CLIENT *Client, const char *Reason )
331 assert( Client != NULL );
332 assert( Reason != NULL );
334 IRC_WriteStrRelatedPrefix( Client, Client, false, "QUIT :%s", Reason );
340 Remove_Client( REMOVE_QUIT, c, Client, Client, Reason, false );
347 Channel_Count( void )
350 unsigned long count = 0;
359 } /* Channel_Count */
363 Channel_MemberCount( CHANNEL *Chan )
366 unsigned long count = 0;
368 assert( Chan != NULL );
370 cl2chan = My_Cl2Chan;
373 if( cl2chan->channel == Chan ) count++;
374 cl2chan = cl2chan->next;
377 } /* Channel_MemberCount */
381 Channel_CountForUser( CLIENT *Client )
383 /* Count number of channels a user is member of. */
388 assert( Client != NULL );
390 cl2chan = My_Cl2Chan;
393 if( cl2chan->client == Client ) count++;
394 cl2chan = cl2chan->next;
398 } /* Channel_CountForUser */
402 Channel_Name( const CHANNEL *Chan )
404 assert( Chan != NULL );
410 Channel_Modes( CHANNEL *Chan )
412 assert( Chan != NULL );
414 } /* Channel_Modes */
418 Channel_Key( CHANNEL *Chan )
420 assert( Chan != NULL );
426 Channel_MaxUsers( CHANNEL *Chan )
428 assert( Chan != NULL );
429 return Chan->maxusers;
430 } /* Channel_MaxUsers */
434 Channel_First( void )
437 } /* Channel_First */
441 Channel_Next( CHANNEL *Chan )
443 assert( Chan != NULL );
449 Channel_Search( const char *Name )
451 /* Search channel structure */
456 assert( Name != NULL );
458 search_hash = Hash( Name );
462 if( search_hash == c->hash )
465 if( strcasecmp( Name, c->name ) == 0 ) return c;
470 } /* Channel_Search */
474 Channel_FirstMember( CHANNEL *Chan )
476 assert( Chan != NULL );
477 return Get_First_Cl2Chan( NULL, Chan );
478 } /* Channel_FirstMember */
482 Channel_NextMember( CHANNEL *Chan, CL2CHAN *Cl2Chan )
484 assert( Chan != NULL );
485 assert( Cl2Chan != NULL );
486 return Get_Next_Cl2Chan( Cl2Chan->next, NULL, Chan );
487 } /* Channel_NextMember */
491 Channel_FirstChannelOf( CLIENT *Client )
493 assert( Client != NULL );
494 return Get_First_Cl2Chan( Client, NULL );
495 } /* Channel_FirstChannelOf */
499 Channel_NextChannelOf( CLIENT *Client, CL2CHAN *Cl2Chan )
501 assert( Client != NULL );
502 assert( Cl2Chan != NULL );
503 return Get_Next_Cl2Chan( Cl2Chan->next, Client, NULL );
504 } /* Channel_NextChannelOf */
508 Channel_GetClient( CL2CHAN *Cl2Chan )
510 assert( Cl2Chan != NULL );
511 return Cl2Chan->client;
512 } /* Channel_GetClient */
516 Channel_GetChannel( CL2CHAN *Cl2Chan )
518 assert( Cl2Chan != NULL );
519 return Cl2Chan->channel;
520 } /* Channel_GetChannel */
524 Channel_IsValidName( const char *Name )
526 assert( Name != NULL );
529 if (strlen(Name) <= 1)
532 if (strchr("#&+", Name[0]) == NULL)
534 if (strlen(Name) >= CHANNEL_NAME_LEN)
537 return Name[strcspn(Name, " ,:\007")] == 0;
538 } /* Channel_IsValidName */
542 Channel_ModeAdd( CHANNEL *Chan, char Mode )
545 * If the channel already had this mode, return false.
546 * If the channel mode was newly set return true.
551 assert( Chan != NULL );
553 x[0] = Mode; x[1] = '\0';
554 if( ! strchr( Chan->modes, x[0] ))
556 /* Channel does not have this mode yet, set it */
557 strlcat( Chan->modes, x, sizeof( Chan->modes ));
561 } /* Channel_ModeAdd */
565 Channel_ModeDel( CHANNEL *Chan, char Mode )
568 * if the mode was removed return true.
569 * if the channel did not have the mode, return false.
573 assert( Chan != NULL );
575 p = strchr( Chan->modes, Mode );
576 if( ! p ) return false;
578 /* Channel has mode -> delete */
585 } /* Channel_ModeDel */
589 Channel_UserModeAdd( CHANNEL *Chan, CLIENT *Client, char Mode )
591 /* Set Channel-User-Mode.
592 * if mode was newly set, return true.
593 * if the User already had this channel-mode, return false.
599 assert( Chan != NULL );
600 assert( Client != NULL );
602 cl2chan = Get_Cl2Chan( Chan, Client );
603 assert( cl2chan != NULL );
605 x[0] = Mode; x[1] = '\0';
606 if( ! strchr( cl2chan->modes, x[0] ))
608 /* mode not set, -> set it */
609 strlcat( cl2chan->modes, x, sizeof( cl2chan->modes ));
613 } /* Channel_UserModeAdd */
617 Channel_UserModeDel( CHANNEL *Chan, CLIENT *Client, char Mode )
619 /* Delete Channel-User-Mode.
620 * If Mode was removed, return true.
621 * If User did not have the Channel-Mode, return false.
627 assert( Chan != NULL );
628 assert( Client != NULL );
630 cl2chan = Get_Cl2Chan( Chan, Client );
631 assert( cl2chan != NULL );
633 p = strchr( cl2chan->modes, Mode );
634 if( ! p ) return false;
636 /* Client has Mode -> delete */
643 } /* Channel_UserModeDel */
647 Channel_UserModes( CHANNEL *Chan, CLIENT *Client )
649 /* return Users' Channel-Modes */
653 assert( Chan != NULL );
654 assert( Client != NULL );
656 cl2chan = Get_Cl2Chan( Chan, Client );
657 assert( cl2chan != NULL );
659 return cl2chan->modes;
660 } /* Channel_UserModes */
664 Channel_IsMemberOf( CHANNEL *Chan, CLIENT *Client )
666 /* Test if Client is on Channel Chan */
668 assert( Chan != NULL );
669 assert( Client != NULL );
670 return Get_Cl2Chan(Chan, Client) != NULL;
671 } /* Channel_IsMemberOf */
675 Channel_Topic( CHANNEL *Chan )
678 assert( Chan != NULL );
679 ret = array_start(&Chan->topic);
680 return ret ? ret : "";
681 } /* Channel_Topic */
687 Channel_TopicTime(CHANNEL *Chan)
689 assert(Chan != NULL);
690 return (unsigned int) Chan->topic_time;
691 } /* Channel_TopicTime */
695 Channel_TopicWho(CHANNEL *Chan)
697 assert(Chan != NULL);
698 return Chan->topic_who;
699 } /* Channel_TopicWho */
705 Channel_SetTopic(CHANNEL *Chan, CLIENT *Client, const char *Topic)
708 assert( Chan != NULL );
709 assert( Topic != NULL );
712 if (len < array_bytes(&Chan->topic))
713 array_free(&Chan->topic);
715 if (len >= COMMAND_LEN || !array_copyb(&Chan->topic, Topic, len+1))
716 Log(LOG_WARNING, "could not set new Topic \"%s\" on %s: %s",
717 Topic, Chan->name, strerror(errno));
719 Chan->topic_time = time(NULL);
720 if (Client != NULL && Client_Type(Client) != CLIENT_SERVER)
721 strlcpy(Chan->topic_who, Client_ID(Client),
722 sizeof Chan->topic_who);
724 strlcpy(Chan->topic_who, DEFAULT_TOPIC_ID,
725 sizeof Chan->topic_who);
729 } /* Channel_SetTopic */
733 Channel_SetModes( CHANNEL *Chan, const char *Modes )
735 assert( Chan != NULL );
736 assert( Modes != NULL );
738 strlcpy( Chan->modes, Modes, sizeof( Chan->modes ));
739 } /* Channel_SetModes */
743 Channel_SetKey( CHANNEL *Chan, const char *Key )
745 assert( Chan != NULL );
746 assert( Key != NULL );
748 strlcpy( Chan->key, Key, sizeof( Chan->key ));
749 LogDebug("Channel %s: Key is now \"%s\".", Chan->name, Chan->key );
750 } /* Channel_SetKey */
754 Channel_SetMaxUsers(CHANNEL *Chan, unsigned long Count)
756 assert( Chan != NULL );
758 Chan->maxusers = Count;
759 LogDebug("Channel %s: Member limit is now %lu.", Chan->name, Chan->maxusers );
760 } /* Channel_SetMaxUsers */
764 Can_Send_To_Channel(CHANNEL *Chan, CLIENT *From)
766 bool is_member, has_voice, is_op;
768 is_member = has_voice = is_op = false;
770 /* The server itself always can send messages :-) */
771 if (Client_ThisServer() == From)
774 if (Channel_IsMemberOf(Chan, From)) {
776 if (strchr(Channel_UserModes(Chan, From), 'v'))
778 if (strchr(Channel_UserModes(Chan, From), 'o'))
783 * Is the client allowed to write to channel?
785 * If channel mode n set: non-members cannot send to channel.
786 * If channel mode m set: need voice.
788 if (strchr(Channel_Modes(Chan), 'n') && !is_member)
791 if (is_op || has_voice)
794 if (strchr(Channel_Modes(Chan), 'm'))
797 return !Lists_Check(&Chan->list_bans, From);
802 Channel_Write(CHANNEL *Chan, CLIENT *From, CLIENT *Client, const char *Command,
803 bool SendErrors, const char *Text)
805 if (!Can_Send_To_Channel(Chan, From)) {
807 return CONNECTED; /* no error, see RFC 2812 */
808 return IRC_WriteStrClient(From, ERR_CANNOTSENDTOCHAN_MSG,
809 Client_ID(From), Channel_Name(Chan));
812 if (Client_Conn(From) > NONE)
813 Conn_UpdateIdle(Client_Conn(From));
815 return IRC_WriteStrChannelPrefix(Client, Chan, From, true,
816 "%s %s :%s", Command, Channel_Name(Chan), Text);
821 Channel_Create( const char *Name )
823 /* Create new CHANNEL structure and add it to linked list */
826 assert( Name != NULL );
828 c = (CHANNEL *)malloc( sizeof( CHANNEL ));
831 Log( LOG_EMERG, "Can't allocate memory! [New_Chan]" );
834 memset( c, 0, sizeof( CHANNEL ));
835 strlcpy( c->name, Name, sizeof( c->name ));
836 c->hash = Hash( c->name );
837 c->next = My_Channels;
839 LogDebug("Created new channel structure for \"%s\".", Name);
841 } /* Channel_Create */
845 Get_Cl2Chan( CHANNEL *Chan, CLIENT *Client )
849 assert( Chan != NULL );
850 assert( Client != NULL );
852 cl2chan = My_Cl2Chan;
855 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) return cl2chan;
856 cl2chan = cl2chan->next;
863 Add_Client( CHANNEL *Chan, CLIENT *Client )
867 assert( Chan != NULL );
868 assert( Client != NULL );
870 /* Create new CL2CHAN structure */
871 cl2chan = (CL2CHAN *)malloc( sizeof( CL2CHAN ));
874 Log( LOG_EMERG, "Can't allocate memory! [Add_Client]" );
877 cl2chan->channel = Chan;
878 cl2chan->client = Client;
879 strcpy( cl2chan->modes, "" );
882 cl2chan->next = My_Cl2Chan;
883 My_Cl2Chan = cl2chan;
885 LogDebug("User \"%s\" joined channel \"%s\".", Client_Mask(Client), Chan->name);
892 Remove_Client( int Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, const char *Reason, bool InformServer )
894 CL2CHAN *cl2chan, *last_cl2chan;
897 assert( Chan != NULL );
898 assert( Client != NULL );
899 assert( Origin != NULL );
900 assert( Reason != NULL );
902 /* Do not inform other servers if the channel is local to this server,
903 * regardless of what the caller requested! */
905 InformServer = !Channel_IsLocal(Chan);
908 cl2chan = My_Cl2Chan;
911 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) break;
912 last_cl2chan = cl2chan;
913 cl2chan = cl2chan->next;
915 if( ! cl2chan ) return false;
917 c = cl2chan->channel;
920 /* maintain cl2chan list */
921 if( last_cl2chan ) last_cl2chan->next = cl2chan->next;
922 else My_Cl2Chan = cl2chan->next;
928 /* QUIT: other servers have already been notified,
929 * see Client_Destroy(); so only inform other clients
930 * in same channel. */
931 assert( InformServer == false );
932 LogDebug("User \"%s\" left channel \"%s\" (%s).",
933 Client_Mask( Client ), c->name, Reason );
936 /* User was KICKed: inform other servers (public
937 * channels) and all users in the channel */
939 IRC_WriteStrServersPrefix( Client_NextHop( Origin ),
940 Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason);
941 IRC_WriteStrChannelPrefix(Client, c, Origin, false, "KICK %s %s :%s",
942 c->name, Client_ID( Client ), Reason );
943 if ((Client_Conn(Client) > NONE) &&
944 (Client_Type(Client) == CLIENT_USER))
946 IRC_WriteStrClientPrefix(Client, Origin, "KICK %s %s :%s",
947 c->name, Client_ID( Client ), Reason);
949 LogDebug("User \"%s\" has been kicked off \"%s\" by \"%s\": %s.",
950 Client_Mask( Client ), c->name, Client_ID(Origin), Reason);
954 IRC_WriteStrServersPrefix(Origin, Client, "PART %s :%s", c->name, Reason);
956 IRC_WriteStrChannelPrefix(Origin, c, Client, false, "PART %s :%s",
959 if ((Client_Conn(Origin) > NONE) &&
960 (Client_Type(Origin) == CLIENT_USER))
962 IRC_WriteStrClientPrefix( Origin, Client, "PART %s :%s", c->name, Reason);
963 LogDebug("User \"%s\" left channel \"%s\" (%s).",
964 Client_Mask(Client), c->name, Reason);
968 /* When channel is empty and is not pre-defined, delete */
969 if( ! strchr( Channel_Modes( Chan ), 'P' ))
971 if( ! Get_First_Cl2Chan( NULL, Chan )) Delete_Channel( Chan );
975 } /* Remove_Client */
979 Channel_AddBan(CHANNEL *c, const char *mask )
981 struct list_head *h = Channel_GetListBans(c);
982 return Lists_Add(h, mask, false);
987 Channel_AddInvite(CHANNEL *c, const char *mask, bool onlyonce)
989 struct list_head *h = Channel_GetListInvites(c);
990 return Lists_Add(h, mask, onlyonce);
995 ShowInvitesBans(struct list_head *head, CLIENT *Client, CHANNEL *Channel, bool invite)
998 char *msg = invite ? RPL_INVITELIST_MSG : RPL_BANLIST_MSG;
1001 assert( Client != NULL );
1002 assert( Channel != NULL );
1004 e = Lists_GetFirst(head);
1006 if( ! IRC_WriteStrClient( Client, msg, Client_ID( Client ),
1007 Channel_Name( Channel ), Lists_GetMask(e) )) return DISCONNECTED;
1008 e = Lists_GetNext(e);
1011 msg_end = invite ? RPL_ENDOFINVITELIST_MSG : RPL_ENDOFBANLIST_MSG;
1012 return IRC_WriteStrClient( Client, msg_end, Client_ID( Client ), Channel_Name( Channel ));
1017 Channel_ShowBans( CLIENT *Client, CHANNEL *Channel )
1019 struct list_head *h;
1021 assert( Channel != NULL );
1023 h = Channel_GetListBans(Channel);
1024 return ShowInvitesBans(h, Client, Channel, false);
1029 Channel_ShowInvites( CLIENT *Client, CHANNEL *Channel )
1031 struct list_head *h;
1033 assert( Channel != NULL );
1035 h = Channel_GetListInvites(Channel);
1036 return ShowInvitesBans(h, Client, Channel, true);
1041 * Log a message to the local &SERVER channel, if it exists.
1044 Channel_LogServer(const char *msg)
1049 assert(msg != NULL);
1051 sc = Channel_Search("&SERVER");
1055 c = Client_ThisServer();
1056 Channel_Write(sc, c, c, "PRIVMSG", false, msg);
1057 } /* Channel_LogServer */
1061 Channel_CheckKey(CHANNEL *Chan, CLIENT *Client, const char *Key)
1063 char *file_name, line[COMMAND_LEN], *nick, *pass;
1066 assert(Chan != NULL);
1067 assert(Client != NULL);
1068 assert(Key != NULL);
1070 if (!strchr(Chan->modes, 'k'))
1072 if (strcmp(Chan->key, Key) == 0)
1077 file_name = array_start(&Chan->keyfile);
1080 fd = fopen(file_name, "r");
1082 Log(LOG_ERR, "Can't open channel key file \"%s\" for %s: %s",
1083 file_name, Chan->name, strerror(errno));
1087 while (fgets(line, (int)sizeof(line), fd) != NULL) {
1089 if (! (nick = strchr(line, ':')))
1092 if (!Match(line, Client_User(Client)))
1094 if (! (pass = strchr(nick, ':')))
1097 if (!Match(nick, Client_ID(Client)))
1099 if (strcmp(Key, pass) != 0)
1107 } /* Channel_CheckKey */
1111 Get_First_Cl2Chan( CLIENT *Client, CHANNEL *Chan )
1113 return Get_Next_Cl2Chan( My_Cl2Chan, Client, Chan );
1114 } /* Get_First_Cl2Chan */
1118 Get_Next_Cl2Chan( CL2CHAN *Start, CLIENT *Client, CHANNEL *Channel )
1122 assert( Client != NULL || Channel != NULL );
1127 if(( Client ) && ( cl2chan->client == Client )) return cl2chan;
1128 if(( Channel ) && ( cl2chan->channel == Channel )) return cl2chan;
1129 cl2chan = cl2chan->next;
1132 } /* Get_Next_Cl2Chan */
1136 * Remove a channel and free all of its data structures.
1139 Delete_Channel(CHANNEL *Chan)
1141 CHANNEL *chan, *last_chan;
1152 assert(chan != NULL);
1156 /* maintain channel list */
1158 last_chan->next = chan->next;
1160 My_Channels = chan->next;
1162 LogDebug("Freed channel structure for \"%s\".", Chan->name);
1164 } /* Delete_Channel */
1168 Set_KeyFile(CHANNEL *Chan, const char *KeyFile)
1172 assert(Chan != NULL);
1173 assert(KeyFile != NULL);
1175 len = strlen(KeyFile);
1176 if (len < array_bytes(&Chan->keyfile)) {
1177 Log(LOG_INFO, "Channel key file of %s removed.", Chan->name);
1178 array_free(&Chan->keyfile);
1184 if (!array_copyb(&Chan->keyfile, KeyFile, len+1))
1186 "Could not set new channel key file \"%s\" for %s: %s",
1187 KeyFile, Chan->name, strerror(errno));
1189 Log(LOG_INFO|LOG_snotice,
1190 "New local channel key file \"%s\" for %s activated.",
1191 KeyFile, Chan->name);