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"
53 static CHANNEL *My_Channels;
54 static CL2CHAN *My_Cl2Chan;
57 static CL2CHAN *Get_Cl2Chan PARAMS(( CHANNEL *Chan, CLIENT *Client ));
58 static CL2CHAN *Add_Client PARAMS(( CHANNEL *Chan, CLIENT *Client ));
59 static bool Remove_Client PARAMS(( int Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, const char *Reason, bool InformServer ));
60 static CL2CHAN *Get_First_Cl2Chan PARAMS(( CLIENT *Client, CHANNEL *Chan ));
61 static CL2CHAN *Get_Next_Cl2Chan PARAMS(( CL2CHAN *Start, CLIENT *Client, CHANNEL *Chan ));
62 static void Delete_Channel PARAMS(( CHANNEL *Chan ));
63 static void Free_Channel PARAMS(( CHANNEL *Chan ));
64 static void Set_KeyFile PARAMS((CHANNEL *Chan, const char *KeyFile));
75 sc = Channel_Create("&SERVER");
77 Channel_SetModes(sc, "mnPt");
78 Channel_SetTopic(sc, Client_ThisServer(), "Server Messages");
83 GLOBAL struct list_head *
84 Channel_GetListBans(CHANNEL *c)
91 GLOBAL struct list_head *
92 Channel_GetListInvites(CHANNEL *c)
95 return &c->list_invites;
100 Channel_InitPredefined( void )
102 /* Generate predefined persistent channels */
105 const struct Conf_Channel *conf_chan;
107 size_t i, channel_count = array_length(&Conf_Channels, sizeof(*conf_chan));
109 conf_chan = array_start(&Conf_Channels);
111 assert(channel_count == 0 || conf_chan != NULL);
113 for (i = 0; i < channel_count; i++, conf_chan++) {
114 if (!conf_chan->name[0] || !Channel_IsValidName(conf_chan->name)) {
115 Log(LOG_ERR, "Can't create pre-defined channel: invalid name: \"%s\"",
120 new_chan = Channel_Search(conf_chan->name);
123 "Can't create pre-defined channel \"%s\": name already in use.",
125 Set_KeyFile(new_chan, conf_chan->keyfile);
129 new_chan = Channel_Create(conf_chan->name);
131 Log(LOG_ERR, "Can't create pre-defined channel \"%s\"",
135 Log(LOG_INFO, "Created pre-defined channel \"%s\"",
138 Channel_ModeAdd(new_chan, 'P');
140 if (conf_chan->topic[0])
141 Channel_SetTopic(new_chan, NULL, conf_chan->topic);
143 c = conf_chan->modes;
145 Channel_ModeAdd(new_chan, *c++);
147 Channel_SetKey(new_chan, conf_chan->key);
148 Channel_SetMaxUsers(new_chan, conf_chan->maxusers);
149 Set_KeyFile(new_chan, conf_chan->keyfile);
152 array_free(&Conf_Channels);
153 } /* Channel_InitPredefined */
157 Free_Channel(CHANNEL *chan)
159 array_free(&chan->topic);
160 array_free(&chan->keyfile);
161 Lists_Free(&chan->list_bans);
162 Lists_Free(&chan->list_invites);
172 CL2CHAN *cl2chan, *cl2chan_next;
174 /* free struct Channel */
182 /* Free Channel allocation table */
183 cl2chan = My_Cl2Chan;
185 cl2chan_next = cl2chan->next;
187 cl2chan = cl2chan_next;
194 * This function lets a client join a channel. First, the function
195 * checks that the specified channel name is valid and that the client
196 * isn't already a member. If the specified channel doesn't exist,
197 * a new channel is created. Client is added to channel by function
201 Channel_Join( CLIENT *Client, const char *Name )
205 assert(Client != NULL);
206 assert(Name != NULL);
208 /* Check that the channel name is valid */
209 if (! Channel_IsValidName(Name)) {
210 IRC_WriteStrClient(Client, ERR_NOSUCHCHANNEL_MSG,
211 Client_ID(Client), Name);
215 chan = Channel_Search(Name);
217 /* Check if the client is already in the channel */
218 if (Get_Cl2Chan(chan, Client))
221 /* If the specified channel does not exist, the channel
223 chan = Channel_Create(Name);
228 /* Add user to Channel */
229 if (! Add_Client(chan, Client))
237 * Part client from channel.
238 * This function lets a client part from a channel. First, the function checks
239 * if the channel exists and the client is a member of it and sends out
240 * appropriate error messages if not. The real work is done by the function
244 Channel_Part(CLIENT * Client, CLIENT * Origin, const char *Name, const char *Reason)
248 assert(Client != NULL);
249 assert(Name != NULL);
250 assert(Reason != NULL);
252 /* Check that specified channel exists */
253 chan = Channel_Search(Name);
255 IRC_WriteStrClient(Client, ERR_NOSUCHCHANNEL_MSG,
256 Client_ID(Client), Name);
260 /* Check that the client is in the channel */
261 if (!Get_Cl2Chan(chan, Client)) {
262 IRC_WriteStrClient(Client, ERR_NOTONCHANNEL_MSG,
263 Client_ID(Client), Name);
267 /* Part client from channel */
268 if (!Remove_Client(REMOVE_PART, chan, Client, Origin, Reason, true))
276 * Kick user from Channel
279 Channel_Kick(CLIENT *Peer, CLIENT *Target, CLIENT *Origin, const char *Name,
284 assert(Peer != NULL);
285 assert(Target != NULL);
286 assert(Origin != NULL);
287 assert(Name != NULL);
288 assert(Reason != NULL);
290 /* Check that channel exists */
291 chan = Channel_Search( Name );
294 IRC_WriteStrClient( Origin, ERR_NOSUCHCHANNEL_MSG, Client_ID( Origin ), Name );
298 if (Client_Type(Peer) != CLIENT_SERVER &&
299 Client_Type(Origin) != CLIENT_SERVICE) {
300 /* Check that user is on the specified channel */
301 if (!Channel_IsMemberOf(chan, Origin)) {
302 IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG,
303 Client_ID(Origin), Name);
307 /* Check if user has operator status */
308 if (!strchr(Channel_UserModes(chan, Origin), 'o')) {
309 IRC_WriteStrClient(Origin, ERR_CHANOPRIVSNEEDED_MSG,
310 Client_ID(Origin), Name);
315 /* Check that the client to be kicked is on the specified channel */
316 if (!Channel_IsMemberOf(chan, Target)) {
317 IRC_WriteStrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
318 Client_ID(Origin), Client_ID(Target), Name );
322 /* Kick Client from channel */
323 Remove_Client( REMOVE_KICK, chan, Target, Origin, Reason, true);
328 Channel_Quit( CLIENT *Client, const char *Reason )
332 assert( Client != NULL );
333 assert( Reason != NULL );
335 IRC_WriteStrRelatedPrefix( Client, Client, false, "QUIT :%s", Reason );
341 Remove_Client( REMOVE_QUIT, c, Client, Client, Reason, false );
348 Channel_Count( void )
351 unsigned long count = 0;
360 } /* Channel_Count */
364 Channel_MemberCount( CHANNEL *Chan )
367 unsigned long count = 0;
369 assert( Chan != NULL );
371 cl2chan = My_Cl2Chan;
374 if( cl2chan->channel == Chan ) count++;
375 cl2chan = cl2chan->next;
378 } /* Channel_MemberCount */
382 Channel_CountForUser( CLIENT *Client )
384 /* Count number of channels a user is member of. */
389 assert( Client != NULL );
391 cl2chan = My_Cl2Chan;
394 if( cl2chan->client == Client ) count++;
395 cl2chan = cl2chan->next;
399 } /* Channel_CountForUser */
403 Channel_Name( const CHANNEL *Chan )
405 assert( Chan != NULL );
411 Channel_Modes( CHANNEL *Chan )
413 assert( Chan != NULL );
415 } /* Channel_Modes */
419 Channel_Key( CHANNEL *Chan )
421 assert( Chan != NULL );
427 Channel_MaxUsers( CHANNEL *Chan )
429 assert( Chan != NULL );
430 return Chan->maxusers;
431 } /* Channel_MaxUsers */
435 Channel_First( void )
438 } /* Channel_First */
442 Channel_Next( CHANNEL *Chan )
444 assert( Chan != NULL );
450 Channel_Search( const char *Name )
452 /* Search channel structure */
457 assert( Name != NULL );
459 search_hash = Hash( Name );
463 if( search_hash == c->hash )
466 if( strcasecmp( Name, c->name ) == 0 ) return c;
471 } /* Channel_Search */
475 Channel_FirstMember( CHANNEL *Chan )
477 assert( Chan != NULL );
478 return Get_First_Cl2Chan( NULL, Chan );
479 } /* Channel_FirstMember */
483 Channel_NextMember( CHANNEL *Chan, CL2CHAN *Cl2Chan )
485 assert( Chan != NULL );
486 assert( Cl2Chan != NULL );
487 return Get_Next_Cl2Chan( Cl2Chan->next, NULL, Chan );
488 } /* Channel_NextMember */
492 Channel_FirstChannelOf( CLIENT *Client )
494 assert( Client != NULL );
495 return Get_First_Cl2Chan( Client, NULL );
496 } /* Channel_FirstChannelOf */
500 Channel_NextChannelOf( CLIENT *Client, CL2CHAN *Cl2Chan )
502 assert( Client != NULL );
503 assert( Cl2Chan != NULL );
504 return Get_Next_Cl2Chan( Cl2Chan->next, Client, NULL );
505 } /* Channel_NextChannelOf */
509 Channel_GetClient( CL2CHAN *Cl2Chan )
511 assert( Cl2Chan != NULL );
512 return Cl2Chan->client;
513 } /* Channel_GetClient */
517 Channel_GetChannel( CL2CHAN *Cl2Chan )
519 assert( Cl2Chan != NULL );
520 return Cl2Chan->channel;
521 } /* Channel_GetChannel */
525 Channel_IsValidName( const char *Name )
527 assert( Name != NULL );
530 if (strlen(Name) <= 1)
533 if (strchr("#&+", Name[0]) == NULL)
535 if (strlen(Name) >= CHANNEL_NAME_LEN)
538 return Name[strcspn(Name, " ,:\007")] == 0;
539 } /* Channel_IsValidName */
543 Channel_ModeAdd( CHANNEL *Chan, char Mode )
546 * If the channel already had this mode, return false.
547 * If the channel mode was newly set return true.
552 assert( Chan != NULL );
554 x[0] = Mode; x[1] = '\0';
555 if( ! strchr( Chan->modes, x[0] ))
557 /* Channel does not have this mode yet, set it */
558 strlcat( Chan->modes, x, sizeof( Chan->modes ));
562 } /* Channel_ModeAdd */
566 Channel_ModeDel( CHANNEL *Chan, char Mode )
569 * if the mode was removed return true.
570 * if the channel did not have the mode, return false.
574 assert( Chan != NULL );
576 p = strchr( Chan->modes, Mode );
577 if( ! p ) return false;
579 /* Channel has mode -> delete */
586 } /* Channel_ModeDel */
590 Channel_UserModeAdd( CHANNEL *Chan, CLIENT *Client, char Mode )
592 /* Set Channel-User-Mode.
593 * if mode was newly set, return true.
594 * if the User already had this channel-mode, return false.
600 assert( Chan != NULL );
601 assert( Client != NULL );
603 cl2chan = Get_Cl2Chan( Chan, Client );
604 assert( cl2chan != NULL );
606 x[0] = Mode; x[1] = '\0';
607 if( ! strchr( cl2chan->modes, x[0] ))
609 /* mode not set, -> set it */
610 strlcat( cl2chan->modes, x, sizeof( cl2chan->modes ));
614 } /* Channel_UserModeAdd */
618 Channel_UserModeDel( CHANNEL *Chan, CLIENT *Client, char Mode )
620 /* Delete Channel-User-Mode.
621 * If Mode was removed, return true.
622 * If User did not have the Channel-Mode, return false.
628 assert( Chan != NULL );
629 assert( Client != NULL );
631 cl2chan = Get_Cl2Chan( Chan, Client );
632 assert( cl2chan != NULL );
634 p = strchr( cl2chan->modes, Mode );
635 if( ! p ) return false;
637 /* Client has Mode -> delete */
644 } /* Channel_UserModeDel */
648 Channel_UserModes( CHANNEL *Chan, CLIENT *Client )
650 /* return Users' Channel-Modes */
654 assert( Chan != NULL );
655 assert( Client != NULL );
657 cl2chan = Get_Cl2Chan( Chan, Client );
658 assert( cl2chan != NULL );
660 return cl2chan->modes;
661 } /* Channel_UserModes */
665 Channel_IsMemberOf( CHANNEL *Chan, CLIENT *Client )
667 /* Test if Client is on Channel Chan */
669 assert( Chan != NULL );
670 assert( Client != NULL );
671 return Get_Cl2Chan(Chan, Client) != NULL;
672 } /* Channel_IsMemberOf */
676 Channel_Topic( CHANNEL *Chan )
679 assert( Chan != NULL );
680 ret = array_start(&Chan->topic);
681 return ret ? ret : "";
682 } /* Channel_Topic */
688 Channel_TopicTime(CHANNEL *Chan)
690 assert(Chan != NULL);
691 return (unsigned int) Chan->topic_time;
692 } /* Channel_TopicTime */
696 Channel_TopicWho(CHANNEL *Chan)
698 assert(Chan != NULL);
699 return Chan->topic_who;
700 } /* Channel_TopicWho */
706 Channel_SetTopic(CHANNEL *Chan, CLIENT *Client, const char *Topic)
709 assert( Chan != NULL );
710 assert( Topic != NULL );
713 if (len < array_bytes(&Chan->topic))
714 array_free(&Chan->topic);
716 if (len >= COMMAND_LEN || !array_copyb(&Chan->topic, Topic, len+1))
717 Log(LOG_WARNING, "could not set new Topic \"%s\" on %s: %s",
718 Topic, Chan->name, strerror(errno));
720 Chan->topic_time = time(NULL);
721 if (Client != NULL && Client_Type(Client) != CLIENT_SERVER)
722 strlcpy(Chan->topic_who, Client_ID(Client),
723 sizeof Chan->topic_who);
725 strlcpy(Chan->topic_who, DEFAULT_TOPIC_ID,
726 sizeof Chan->topic_who);
730 } /* Channel_SetTopic */
734 Channel_SetModes( CHANNEL *Chan, const char *Modes )
736 assert( Chan != NULL );
737 assert( Modes != NULL );
739 strlcpy( Chan->modes, Modes, sizeof( Chan->modes ));
740 } /* Channel_SetModes */
744 Channel_SetKey( CHANNEL *Chan, const char *Key )
746 assert( Chan != NULL );
747 assert( Key != NULL );
749 strlcpy( Chan->key, Key, sizeof( Chan->key ));
750 LogDebug("Channel %s: Key is now \"%s\".", Chan->name, Chan->key );
751 } /* Channel_SetKey */
755 Channel_SetMaxUsers(CHANNEL *Chan, unsigned long Count)
757 assert( Chan != NULL );
759 Chan->maxusers = Count;
760 LogDebug("Channel %s: Member limit is now %lu.", Chan->name, Chan->maxusers );
761 } /* Channel_SetMaxUsers */
765 Can_Send_To_Channel(CHANNEL *Chan, CLIENT *From)
767 bool is_member, has_voice, is_op;
769 is_member = has_voice = is_op = false;
771 /* The server itself always can send messages :-) */
772 if (Client_ThisServer() == From)
775 if (Channel_IsMemberOf(Chan, From)) {
777 if (strchr(Channel_UserModes(Chan, From), 'v'))
779 if (strchr(Channel_UserModes(Chan, From), 'o'))
784 * Is the client allowed to write to channel?
786 * If channel mode n set: non-members cannot send to channel.
787 * If channel mode m set: need voice.
789 if (strchr(Channel_Modes(Chan), 'n') && !is_member)
792 if (is_op || has_voice)
795 if (strchr(Channel_Modes(Chan), 'm'))
798 return !Lists_Check(&Chan->list_bans, From);
803 Channel_Write(CHANNEL *Chan, CLIENT *From, CLIENT *Client, const char *Command,
804 bool SendErrors, const char *Text)
806 if (!Can_Send_To_Channel(Chan, From)) {
808 return CONNECTED; /* no error, see RFC 2812 */
809 return IRC_WriteStrClient(From, ERR_CANNOTSENDTOCHAN_MSG,
810 Client_ID(From), Channel_Name(Chan));
813 if (Client_Conn(From) > NONE)
814 Conn_UpdateIdle(Client_Conn(From));
816 return IRC_WriteStrChannelPrefix(Client, Chan, From, true,
817 "%s %s :%s", Command, Channel_Name(Chan), Text);
822 Channel_Create( const char *Name )
824 /* Create new CHANNEL structure and add it to linked list */
827 assert( Name != NULL );
829 c = (CHANNEL *)malloc( sizeof( CHANNEL ));
832 Log( LOG_EMERG, "Can't allocate memory! [New_Chan]" );
835 memset( c, 0, sizeof( CHANNEL ));
836 strlcpy( c->name, Name, sizeof( c->name ));
837 c->hash = Hash( c->name );
838 c->next = My_Channels;
840 LogDebug("Created new channel structure for \"%s\".", Name);
842 } /* Channel_Create */
846 Get_Cl2Chan( CHANNEL *Chan, CLIENT *Client )
850 assert( Chan != NULL );
851 assert( Client != NULL );
853 cl2chan = My_Cl2Chan;
856 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) return cl2chan;
857 cl2chan = cl2chan->next;
864 Add_Client( CHANNEL *Chan, CLIENT *Client )
868 assert( Chan != NULL );
869 assert( Client != NULL );
871 /* Create new CL2CHAN structure */
872 cl2chan = (CL2CHAN *)malloc( sizeof( CL2CHAN ));
875 Log( LOG_EMERG, "Can't allocate memory! [Add_Client]" );
878 cl2chan->channel = Chan;
879 cl2chan->client = Client;
880 strcpy( cl2chan->modes, "" );
883 cl2chan->next = My_Cl2Chan;
884 My_Cl2Chan = cl2chan;
886 LogDebug("User \"%s\" joined channel \"%s\".", Client_Mask(Client), Chan->name);
893 Remove_Client( int Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, const char *Reason, bool InformServer )
895 CL2CHAN *cl2chan, *last_cl2chan;
898 assert( Chan != NULL );
899 assert( Client != NULL );
900 assert( Origin != NULL );
901 assert( Reason != NULL );
903 /* Do not inform other servers if the channel is local to this server,
904 * regardless of what the caller requested! */
906 InformServer = !Channel_IsLocal(Chan);
909 cl2chan = My_Cl2Chan;
912 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) break;
913 last_cl2chan = cl2chan;
914 cl2chan = cl2chan->next;
916 if( ! cl2chan ) return false;
918 c = cl2chan->channel;
921 /* maintain cl2chan list */
922 if( last_cl2chan ) last_cl2chan->next = cl2chan->next;
923 else My_Cl2Chan = cl2chan->next;
929 /* QUIT: other servers have already been notified,
930 * see Client_Destroy(); so only inform other clients
931 * in same channel. */
932 assert( InformServer == false );
933 LogDebug("User \"%s\" left channel \"%s\" (%s).",
934 Client_Mask( Client ), c->name, Reason );
937 /* User was KICKed: inform other servers (public
938 * channels) and all users in the channel */
940 IRC_WriteStrServersPrefix( Client_NextHop( Origin ),
941 Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason);
942 IRC_WriteStrChannelPrefix(Client, c, Origin, false, "KICK %s %s :%s",
943 c->name, Client_ID( Client ), Reason );
944 if ((Client_Conn(Client) > NONE) &&
945 (Client_Type(Client) == CLIENT_USER))
947 IRC_WriteStrClientPrefix(Client, Origin, "KICK %s %s :%s",
948 c->name, Client_ID( Client ), Reason);
950 LogDebug("User \"%s\" has been kicked off \"%s\" by \"%s\": %s.",
951 Client_Mask( Client ), c->name, Client_ID(Origin), Reason);
955 IRC_WriteStrServersPrefix(Origin, Client, "PART %s :%s", c->name, Reason);
957 IRC_WriteStrChannelPrefix(Origin, c, Client, false, "PART %s :%s",
960 if ((Client_Conn(Origin) > NONE) &&
961 (Client_Type(Origin) == CLIENT_USER))
963 IRC_WriteStrClientPrefix( Origin, Client, "PART %s :%s", c->name, Reason);
964 LogDebug("User \"%s\" left channel \"%s\" (%s).",
965 Client_Mask(Client), c->name, Reason);
969 /* When channel is empty and is not pre-defined, delete */
970 if( ! strchr( Channel_Modes( Chan ), 'P' ))
972 if( ! Get_First_Cl2Chan( NULL, Chan )) Delete_Channel( Chan );
976 } /* Remove_Client */
980 Channel_AddBan(CHANNEL *c, const char *mask )
982 struct list_head *h = Channel_GetListBans(c);
983 return Lists_Add(h, mask, false);
988 Channel_AddInvite(CHANNEL *c, const char *mask, bool onlyonce)
990 struct list_head *h = Channel_GetListInvites(c);
991 return Lists_Add(h, mask, onlyonce);
996 ShowInvitesBans(struct list_head *head, CLIENT *Client, CHANNEL *Channel, bool invite)
999 char *msg = invite ? RPL_INVITELIST_MSG : RPL_BANLIST_MSG;
1002 assert( Client != NULL );
1003 assert( Channel != NULL );
1005 e = Lists_GetFirst(head);
1007 if( ! IRC_WriteStrClient( Client, msg, Client_ID( Client ),
1008 Channel_Name( Channel ), Lists_GetMask(e) )) return DISCONNECTED;
1009 e = Lists_GetNext(e);
1012 msg_end = invite ? RPL_ENDOFINVITELIST_MSG : RPL_ENDOFBANLIST_MSG;
1013 return IRC_WriteStrClient( Client, msg_end, Client_ID( Client ), Channel_Name( Channel ));
1018 Channel_ShowBans( CLIENT *Client, CHANNEL *Channel )
1020 struct list_head *h;
1022 assert( Channel != NULL );
1024 h = Channel_GetListBans(Channel);
1025 return ShowInvitesBans(h, Client, Channel, false);
1030 Channel_ShowInvites( CLIENT *Client, CHANNEL *Channel )
1032 struct list_head *h;
1034 assert( Channel != NULL );
1036 h = Channel_GetListInvites(Channel);
1037 return ShowInvitesBans(h, Client, Channel, true);
1042 * Log a message to the local &SERVER channel, if it exists.
1045 Channel_LogServer(const char *msg)
1050 assert(msg != NULL);
1052 sc = Channel_Search("&SERVER");
1056 c = Client_ThisServer();
1057 Channel_Write(sc, c, c, "PRIVMSG", false, msg);
1058 } /* Channel_LogServer */
1062 Channel_CheckKey(CHANNEL *Chan, CLIENT *Client, const char *Key)
1064 char *file_name, line[COMMAND_LEN], *nick, *pass;
1067 assert(Chan != NULL);
1068 assert(Client != NULL);
1069 assert(Key != NULL);
1071 if (!strchr(Chan->modes, 'k'))
1073 if (strcmp(Chan->key, Key) == 0)
1078 file_name = array_start(&Chan->keyfile);
1081 fd = fopen(file_name, "r");
1083 Log(LOG_ERR, "Can't open channel key file \"%s\" for %s: %s",
1084 file_name, Chan->name, strerror(errno));
1088 while (fgets(line, sizeof(line), fd) != NULL) {
1090 if (! (nick = strchr(line, ':')))
1093 if (!Match(line, Client_User(Client)))
1095 if (! (pass = strchr(nick, ':')))
1098 if (!Match(nick, Client_ID(Client)))
1100 if (strcmp(Key, pass) != 0)
1108 } /* Channel_CheckKey */
1112 Get_First_Cl2Chan( CLIENT *Client, CHANNEL *Chan )
1114 return Get_Next_Cl2Chan( My_Cl2Chan, Client, Chan );
1115 } /* Get_First_Cl2Chan */
1119 Get_Next_Cl2Chan( CL2CHAN *Start, CLIENT *Client, CHANNEL *Channel )
1123 assert( Client != NULL || Channel != NULL );
1128 if(( Client ) && ( cl2chan->client == Client )) return cl2chan;
1129 if(( Channel ) && ( cl2chan->channel == Channel )) return cl2chan;
1130 cl2chan = cl2chan->next;
1133 } /* Get_Next_Cl2Chan */
1137 * Remove a channel and free all of its data structures.
1140 Delete_Channel(CHANNEL *Chan)
1142 CHANNEL *chan, *last_chan;
1153 assert(chan != NULL);
1157 /* maintain channel list */
1159 last_chan->next = chan->next;
1161 My_Channels = chan->next;
1163 LogDebug("Freed channel structure for \"%s\".", Chan->name);
1165 } /* Delete_Channel */
1169 Set_KeyFile(CHANNEL *Chan, const char *KeyFile)
1173 assert(Chan != NULL);
1174 assert(KeyFile != NULL);
1176 len = strlen(KeyFile);
1177 if (len < array_bytes(&Chan->keyfile)) {
1178 Log(LOG_INFO, "Channel key file of %s removed.", Chan->name);
1179 array_free(&Chan->keyfile);
1185 if (!array_copyb(&Chan->keyfile, KeyFile, len+1))
1187 "Could not set new channel key file \"%s\" for %s: %s",
1188 KeyFile, Chan->name, strerror(errno));
1190 Log(LOG_INFO|LOG_snotice,
1191 "New local channel key file \"%s\" for %s activated.",
1192 KeyFile, Chan->name);