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"
35 #include "irc-write.h"
51 static CHANNEL *My_Channels;
52 static CL2CHAN *My_Cl2Chan;
55 static CL2CHAN *Get_Cl2Chan PARAMS(( CHANNEL *Chan, CLIENT *Client ));
56 static CL2CHAN *Add_Client PARAMS(( CHANNEL *Chan, CLIENT *Client ));
57 static bool Remove_Client PARAMS(( int Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, const char *Reason, bool InformServer ));
58 static CL2CHAN *Get_First_Cl2Chan PARAMS(( CLIENT *Client, CHANNEL *Chan ));
59 static CL2CHAN *Get_Next_Cl2Chan PARAMS(( CL2CHAN *Start, CLIENT *Client, CHANNEL *Chan ));
60 static void Delete_Channel PARAMS(( CHANNEL *Chan ));
61 static void Free_Channel PARAMS(( CHANNEL *Chan ));
62 static void Set_KeyFile PARAMS((CHANNEL *Chan, const char *KeyFile));
73 sc = Channel_Create("&SERVER");
75 Channel_SetModes(sc, "mnPt");
76 Channel_SetTopic(sc, Client_ThisServer(), "Server Messages");
81 GLOBAL struct list_head *
82 Channel_GetListBans(CHANNEL *c)
89 GLOBAL struct list_head *
90 Channel_GetListInvites(CHANNEL *c)
93 return &c->list_invites;
98 Channel_InitPredefined( void )
100 /* Generate predefined persistent channels */
103 const struct Conf_Channel *conf_chan;
105 size_t i, channel_count = array_length(&Conf_Channels, sizeof(*conf_chan));
107 conf_chan = array_start(&Conf_Channels);
109 assert(channel_count == 0 || conf_chan != NULL);
111 for (i = 0; i < channel_count; i++, conf_chan++) {
112 if (!conf_chan->name[0] || !Channel_IsValidName(conf_chan->name)) {
113 Log(LOG_ERR, "Can't create pre-defined channel: invalid name: \"%s\"",
118 new_chan = Channel_Search(conf_chan->name);
121 "Can't create pre-defined channel \"%s\": name already in use.",
123 Set_KeyFile(new_chan, conf_chan->keyfile);
127 new_chan = Channel_Create(conf_chan->name);
129 Log(LOG_ERR, "Can't create pre-defined channel \"%s\"",
133 Log(LOG_INFO, "Created pre-defined channel \"%s\"",
136 Channel_ModeAdd(new_chan, 'P');
138 if (conf_chan->topic[0])
139 Channel_SetTopic(new_chan, NULL, conf_chan->topic);
141 c = conf_chan->modes;
143 Channel_ModeAdd(new_chan, *c++);
145 Channel_SetKey(new_chan, conf_chan->key);
146 Channel_SetMaxUsers(new_chan, conf_chan->maxusers);
147 Set_KeyFile(new_chan, conf_chan->keyfile);
150 array_free(&Conf_Channels);
151 } /* Channel_InitPredefined */
155 Free_Channel(CHANNEL *chan)
157 array_free(&chan->topic);
158 array_free(&chan->keyfile);
159 Lists_Free(&chan->list_bans);
160 Lists_Free(&chan->list_invites);
170 CL2CHAN *cl2chan, *cl2chan_next;
172 /* free struct Channel */
180 /* Free Channel allocation table */
181 cl2chan = My_Cl2Chan;
183 cl2chan_next = cl2chan->next;
185 cl2chan = cl2chan_next;
192 * This function lets a client join a channel. First, the function
193 * checks that the specified channel name is valid and that the client
194 * isn't already a member. If the specified channel doesn't exist,
195 * a new channel is created. Client is added to channel by function
199 Channel_Join( CLIENT *Client, const char *Name )
203 assert(Client != NULL);
204 assert(Name != NULL);
206 /* Check that the channel name is valid */
207 if (! Channel_IsValidName(Name)) {
208 IRC_WriteStrClient(Client, ERR_NOSUCHCHANNEL_MSG,
209 Client_ID(Client), Name);
213 chan = Channel_Search(Name);
215 /* Check if the client is already in the channel */
216 if (Get_Cl2Chan(chan, Client))
219 /* If the specified channel does not exist, the channel
221 chan = Channel_Create(Name);
226 /* Add user to Channel */
227 if (! Add_Client(chan, Client))
235 * Part client from channel.
236 * This function lets a client part from a channel. First, the function checks
237 * if the channel exists and the client is a member of it and sends out
238 * appropriate error messages if not. The real work is done by the function
242 Channel_Part(CLIENT * Client, CLIENT * Origin, const char *Name, const char *Reason)
246 assert(Client != NULL);
247 assert(Name != NULL);
248 assert(Reason != NULL);
250 /* Check that specified channel exists */
251 chan = Channel_Search(Name);
253 IRC_WriteStrClient(Client, ERR_NOSUCHCHANNEL_MSG,
254 Client_ID(Client), Name);
258 /* Check that the client is in the channel */
259 if (!Get_Cl2Chan(chan, Client)) {
260 IRC_WriteStrClient(Client, ERR_NOTONCHANNEL_MSG,
261 Client_ID(Client), Name);
265 /* Part client from channel */
266 if (!Remove_Client(REMOVE_PART, chan, Client, Origin, Reason, true))
274 * Kick user from Channel
277 Channel_Kick(CLIENT *Peer, CLIENT *Target, CLIENT *Origin, const char *Name,
282 assert(Peer != NULL);
283 assert(Target != NULL);
284 assert(Origin != NULL);
285 assert(Name != NULL);
286 assert(Reason != NULL);
288 /* Check that channel exists */
289 chan = Channel_Search( Name );
292 IRC_WriteStrClient( Origin, ERR_NOSUCHCHANNEL_MSG, Client_ID( Origin ), Name );
296 if (Client_Type(Peer) != CLIENT_SERVER &&
297 Client_Type(Origin) != CLIENT_SERVICE) {
298 /* Check that user is on the specified channel */
299 if (!Channel_IsMemberOf(chan, Origin)) {
300 IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG,
301 Client_ID(Origin), Name);
305 /* Check if user has operator status */
306 if (!strchr(Channel_UserModes(chan, Origin), 'o')) {
307 IRC_WriteStrClient(Origin, ERR_CHANOPRIVSNEEDED_MSG,
308 Client_ID(Origin), Name);
313 /* Check that the client to be kicked is on the specified channel */
314 if (!Channel_IsMemberOf(chan, Target)) {
315 IRC_WriteStrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
316 Client_ID(Origin), Client_ID(Target), Name );
320 /* Kick Client from channel */
321 Remove_Client( REMOVE_KICK, chan, Target, Origin, Reason, true);
326 Channel_Quit( CLIENT *Client, const char *Reason )
330 assert( Client != NULL );
331 assert( Reason != NULL );
333 IRC_WriteStrRelatedPrefix( Client, Client, false, "QUIT :%s", Reason );
339 Remove_Client( REMOVE_QUIT, c, Client, Client, Reason, false );
346 Channel_Count( void )
349 unsigned long count = 0;
358 } /* Channel_Count */
362 Channel_MemberCount( CHANNEL *Chan )
365 unsigned long count = 0;
367 assert( Chan != NULL );
369 cl2chan = My_Cl2Chan;
372 if( cl2chan->channel == Chan ) count++;
373 cl2chan = cl2chan->next;
376 } /* Channel_MemberCount */
380 Channel_CountForUser( CLIENT *Client )
382 /* Count number of channels a user is member of. */
387 assert( Client != NULL );
389 cl2chan = My_Cl2Chan;
392 if( cl2chan->client == Client ) count++;
393 cl2chan = cl2chan->next;
397 } /* Channel_CountForUser */
401 Channel_Name( const CHANNEL *Chan )
403 assert( Chan != NULL );
409 Channel_Modes( CHANNEL *Chan )
411 assert( Chan != NULL );
413 } /* Channel_Modes */
417 Channel_Key( CHANNEL *Chan )
419 assert( Chan != NULL );
425 Channel_MaxUsers( CHANNEL *Chan )
427 assert( Chan != NULL );
428 return Chan->maxusers;
429 } /* Channel_MaxUsers */
433 Channel_First( void )
436 } /* Channel_First */
440 Channel_Next( CHANNEL *Chan )
442 assert( Chan != NULL );
448 Channel_Search( const char *Name )
450 /* Search channel structure */
455 assert( Name != NULL );
457 search_hash = Hash( Name );
461 if( search_hash == c->hash )
464 if( strcasecmp( Name, c->name ) == 0 ) return c;
469 } /* Channel_Search */
473 Channel_FirstMember( CHANNEL *Chan )
475 assert( Chan != NULL );
476 return Get_First_Cl2Chan( NULL, Chan );
477 } /* Channel_FirstMember */
481 Channel_NextMember( CHANNEL *Chan, CL2CHAN *Cl2Chan )
483 assert( Chan != NULL );
484 assert( Cl2Chan != NULL );
485 return Get_Next_Cl2Chan( Cl2Chan->next, NULL, Chan );
486 } /* Channel_NextMember */
490 Channel_FirstChannelOf( CLIENT *Client )
492 assert( Client != NULL );
493 return Get_First_Cl2Chan( Client, NULL );
494 } /* Channel_FirstChannelOf */
498 Channel_NextChannelOf( CLIENT *Client, CL2CHAN *Cl2Chan )
500 assert( Client != NULL );
501 assert( Cl2Chan != NULL );
502 return Get_Next_Cl2Chan( Cl2Chan->next, Client, NULL );
503 } /* Channel_NextChannelOf */
507 Channel_GetClient( CL2CHAN *Cl2Chan )
509 assert( Cl2Chan != NULL );
510 return Cl2Chan->client;
511 } /* Channel_GetClient */
515 Channel_GetChannel( CL2CHAN *Cl2Chan )
517 assert( Cl2Chan != NULL );
518 return Cl2Chan->channel;
519 } /* Channel_GetChannel */
523 Channel_IsValidName( const char *Name )
525 assert( Name != NULL );
528 if (strlen(Name) <= 1)
531 if (strchr("#&+", Name[0]) == NULL)
533 if (strlen(Name) >= CHANNEL_NAME_LEN)
536 return Name[strcspn(Name, " ,:\007")] == 0;
537 } /* Channel_IsValidName */
541 Channel_ModeAdd( CHANNEL *Chan, char Mode )
544 * If the channel already had this mode, return false.
545 * If the channel mode was newly set return true.
550 assert( Chan != NULL );
552 x[0] = Mode; x[1] = '\0';
553 if( ! strchr( Chan->modes, x[0] ))
555 /* Channel does not have this mode yet, set it */
556 strlcat( Chan->modes, x, sizeof( Chan->modes ));
560 } /* Channel_ModeAdd */
564 Channel_ModeDel( CHANNEL *Chan, char Mode )
567 * if the mode was removed return true.
568 * if the channel did not have the mode, return false.
572 assert( Chan != NULL );
574 p = strchr( Chan->modes, Mode );
575 if( ! p ) return false;
577 /* Channel has mode -> delete */
584 } /* Channel_ModeDel */
588 Channel_UserModeAdd( CHANNEL *Chan, CLIENT *Client, char Mode )
590 /* Set Channel-User-Mode.
591 * if mode was newly set, return true.
592 * if the User already had this channel-mode, return false.
598 assert( Chan != NULL );
599 assert( Client != NULL );
601 cl2chan = Get_Cl2Chan( Chan, Client );
602 assert( cl2chan != NULL );
604 x[0] = Mode; x[1] = '\0';
605 if( ! strchr( cl2chan->modes, x[0] ))
607 /* mode not set, -> set it */
608 strlcat( cl2chan->modes, x, sizeof( cl2chan->modes ));
612 } /* Channel_UserModeAdd */
616 Channel_UserModeDel( CHANNEL *Chan, CLIENT *Client, char Mode )
618 /* Delete Channel-User-Mode.
619 * If Mode was removed, return true.
620 * If User did not have the Channel-Mode, return false.
626 assert( Chan != NULL );
627 assert( Client != NULL );
629 cl2chan = Get_Cl2Chan( Chan, Client );
630 assert( cl2chan != NULL );
632 p = strchr( cl2chan->modes, Mode );
633 if( ! p ) return false;
635 /* Client has Mode -> delete */
642 } /* Channel_UserModeDel */
646 Channel_UserModes( CHANNEL *Chan, CLIENT *Client )
648 /* return Users' Channel-Modes */
652 assert( Chan != NULL );
653 assert( Client != NULL );
655 cl2chan = Get_Cl2Chan( Chan, Client );
656 assert( cl2chan != NULL );
658 return cl2chan->modes;
659 } /* Channel_UserModes */
663 Channel_IsMemberOf( CHANNEL *Chan, CLIENT *Client )
665 /* Test if Client is on Channel Chan */
667 assert( Chan != NULL );
668 assert( Client != NULL );
669 return Get_Cl2Chan(Chan, Client) != NULL;
670 } /* Channel_IsMemberOf */
674 Channel_Topic( CHANNEL *Chan )
677 assert( Chan != NULL );
678 ret = array_start(&Chan->topic);
679 return ret ? ret : "";
680 } /* Channel_Topic */
686 Channel_TopicTime(CHANNEL *Chan)
688 assert(Chan != NULL);
689 return (unsigned int) Chan->topic_time;
690 } /* Channel_TopicTime */
694 Channel_TopicWho(CHANNEL *Chan)
696 assert(Chan != NULL);
697 return Chan->topic_who;
698 } /* Channel_TopicWho */
704 Channel_SetTopic(CHANNEL *Chan, CLIENT *Client, const char *Topic)
707 assert( Chan != NULL );
708 assert( Topic != NULL );
711 if (len < array_bytes(&Chan->topic))
712 array_free(&Chan->topic);
714 if (len >= COMMAND_LEN || !array_copyb(&Chan->topic, Topic, len+1))
715 Log(LOG_WARNING, "could not set new Topic \"%s\" on %s: %s",
716 Topic, Chan->name, strerror(errno));
718 Chan->topic_time = time(NULL);
719 if (Client != NULL && Client_Type(Client) != CLIENT_SERVER)
720 strlcpy(Chan->topic_who, Client_ID(Client),
721 sizeof Chan->topic_who);
723 strlcpy(Chan->topic_who, DEFAULT_TOPIC_ID,
724 sizeof Chan->topic_who);
728 } /* Channel_SetTopic */
732 Channel_SetModes( CHANNEL *Chan, const char *Modes )
734 assert( Chan != NULL );
735 assert( Modes != NULL );
737 strlcpy( Chan->modes, Modes, sizeof( Chan->modes ));
738 } /* Channel_SetModes */
742 Channel_SetKey( CHANNEL *Chan, const char *Key )
744 assert( Chan != NULL );
745 assert( Key != NULL );
747 strlcpy( Chan->key, Key, sizeof( Chan->key ));
748 LogDebug("Channel %s: Key is now \"%s\".", Chan->name, Chan->key );
749 } /* Channel_SetKey */
753 Channel_SetMaxUsers(CHANNEL *Chan, unsigned long Count)
755 assert( Chan != NULL );
757 Chan->maxusers = Count;
758 LogDebug("Channel %s: Member limit is now %lu.", Chan->name, Chan->maxusers );
759 } /* Channel_SetMaxUsers */
763 Can_Send_To_Channel(CHANNEL *Chan, CLIENT *From)
765 bool is_member, has_voice, is_op;
767 is_member = has_voice = is_op = false;
769 /* The server itself always can send messages :-) */
770 if (Client_ThisServer() == From)
773 if (Channel_IsMemberOf(Chan, From)) {
775 if (strchr(Channel_UserModes(Chan, From), 'v'))
777 if (strchr(Channel_UserModes(Chan, From), 'o'))
782 * Is the client allowed to write to channel?
784 * If channel mode n set: non-members cannot send to channel.
785 * If channel mode m set: need voice.
787 if (strchr(Channel_Modes(Chan), 'n') && !is_member)
790 if (is_op || has_voice)
793 if (strchr(Channel_Modes(Chan), 'm'))
796 return !Lists_Check(&Chan->list_bans, From);
801 Channel_Write(CHANNEL *Chan, CLIENT *From, CLIENT *Client, const char *Command,
802 bool SendErrors, const char *Text)
804 if (!Can_Send_To_Channel(Chan, From)) {
806 return CONNECTED; /* no error, see RFC 2812 */
807 return IRC_WriteStrClient(From, ERR_CANNOTSENDTOCHAN_MSG,
808 Client_ID(From), Channel_Name(Chan));
811 if (Client_Conn(From) > NONE)
812 Conn_UpdateIdle(Client_Conn(From));
814 return IRC_WriteStrChannelPrefix(Client, Chan, From, true,
815 "%s %s :%s", Command, Channel_Name(Chan), Text);
820 Channel_Create( const char *Name )
822 /* Create new CHANNEL structure and add it to linked list */
825 assert( Name != NULL );
827 c = (CHANNEL *)malloc( sizeof( CHANNEL ));
830 Log( LOG_EMERG, "Can't allocate memory! [New_Chan]" );
833 memset( c, 0, sizeof( CHANNEL ));
834 strlcpy( c->name, Name, sizeof( c->name ));
835 c->hash = Hash( c->name );
836 c->next = My_Channels;
838 LogDebug("Created new channel structure for \"%s\".", Name);
840 } /* Channel_Create */
844 Get_Cl2Chan( CHANNEL *Chan, CLIENT *Client )
848 assert( Chan != NULL );
849 assert( Client != NULL );
851 cl2chan = My_Cl2Chan;
854 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) return cl2chan;
855 cl2chan = cl2chan->next;
862 Add_Client( CHANNEL *Chan, CLIENT *Client )
866 assert( Chan != NULL );
867 assert( Client != NULL );
869 /* Create new CL2CHAN structure */
870 cl2chan = (CL2CHAN *)malloc( sizeof( CL2CHAN ));
873 Log( LOG_EMERG, "Can't allocate memory! [Add_Client]" );
876 cl2chan->channel = Chan;
877 cl2chan->client = Client;
878 strcpy( cl2chan->modes, "" );
881 cl2chan->next = My_Cl2Chan;
882 My_Cl2Chan = cl2chan;
884 LogDebug("User \"%s\" joined channel \"%s\".", Client_Mask(Client), Chan->name);
891 Remove_Client( int Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, const char *Reason, bool InformServer )
893 CL2CHAN *cl2chan, *last_cl2chan;
896 assert( Chan != NULL );
897 assert( Client != NULL );
898 assert( Origin != NULL );
899 assert( Reason != NULL );
901 /* Do not inform other servers if the channel is local to this server,
902 * regardless of what the caller requested! */
904 InformServer = !Channel_IsLocal(Chan);
907 cl2chan = My_Cl2Chan;
910 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) break;
911 last_cl2chan = cl2chan;
912 cl2chan = cl2chan->next;
914 if( ! cl2chan ) return false;
916 c = cl2chan->channel;
919 /* maintain cl2chan list */
920 if( last_cl2chan ) last_cl2chan->next = cl2chan->next;
921 else My_Cl2Chan = cl2chan->next;
927 /* QUIT: other servers have already been notified,
928 * see Client_Destroy(); so only inform other clients
929 * in same channel. */
930 assert( InformServer == false );
931 LogDebug("User \"%s\" left channel \"%s\" (%s).",
932 Client_Mask( Client ), c->name, Reason );
935 /* User was KICKed: inform other servers (public
936 * channels) and all users in the channel */
938 IRC_WriteStrServersPrefix( Client_NextHop( Origin ),
939 Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason);
940 IRC_WriteStrChannelPrefix(Client, c, Origin, false, "KICK %s %s :%s",
941 c->name, Client_ID( Client ), Reason );
942 if ((Client_Conn(Client) > NONE) &&
943 (Client_Type(Client) == CLIENT_USER))
945 IRC_WriteStrClientPrefix(Client, Origin, "KICK %s %s :%s",
946 c->name, Client_ID( Client ), Reason);
948 LogDebug("User \"%s\" has been kicked off \"%s\" by \"%s\": %s.",
949 Client_Mask( Client ), c->name, Client_ID(Origin), Reason);
953 IRC_WriteStrServersPrefix(Origin, Client, "PART %s :%s", c->name, Reason);
955 IRC_WriteStrChannelPrefix(Origin, c, Client, false, "PART %s :%s",
958 if ((Client_Conn(Origin) > NONE) &&
959 (Client_Type(Origin) == CLIENT_USER))
961 IRC_WriteStrClientPrefix( Origin, Client, "PART %s :%s", c->name, Reason);
962 LogDebug("User \"%s\" left channel \"%s\" (%s).",
963 Client_Mask(Client), c->name, Reason);
967 /* When channel is empty and is not pre-defined, delete */
968 if( ! strchr( Channel_Modes( Chan ), 'P' ))
970 if( ! Get_First_Cl2Chan( NULL, Chan )) Delete_Channel( Chan );
974 } /* Remove_Client */
978 Channel_AddBan(CHANNEL *c, const char *mask )
980 struct list_head *h = Channel_GetListBans(c);
981 return Lists_Add(h, mask, false);
986 Channel_AddInvite(CHANNEL *c, const char *mask, bool onlyonce)
988 struct list_head *h = Channel_GetListInvites(c);
989 return Lists_Add(h, mask, onlyonce);
994 ShowInvitesBans(struct list_head *head, CLIENT *Client, CHANNEL *Channel, bool invite)
997 char *msg = invite ? RPL_INVITELIST_MSG : RPL_BANLIST_MSG;
1000 assert( Client != NULL );
1001 assert( Channel != NULL );
1003 e = Lists_GetFirst(head);
1005 if( ! IRC_WriteStrClient( Client, msg, Client_ID( Client ),
1006 Channel_Name( Channel ), Lists_GetMask(e) )) return DISCONNECTED;
1007 e = Lists_GetNext(e);
1010 msg_end = invite ? RPL_ENDOFINVITELIST_MSG : RPL_ENDOFBANLIST_MSG;
1011 return IRC_WriteStrClient( Client, msg_end, Client_ID( Client ), Channel_Name( Channel ));
1016 Channel_ShowBans( CLIENT *Client, CHANNEL *Channel )
1018 struct list_head *h;
1020 assert( Channel != NULL );
1022 h = Channel_GetListBans(Channel);
1023 return ShowInvitesBans(h, Client, Channel, false);
1028 Channel_ShowInvites( CLIENT *Client, CHANNEL *Channel )
1030 struct list_head *h;
1032 assert( Channel != NULL );
1034 h = Channel_GetListInvites(Channel);
1035 return ShowInvitesBans(h, Client, Channel, true);
1040 * Log a message to the local &SERVER channel, if it exists.
1043 Channel_LogServer(const char *msg)
1048 assert(msg != NULL);
1050 sc = Channel_Search("&SERVER");
1054 c = Client_ThisServer();
1055 Channel_Write(sc, c, c, "PRIVMSG", false, msg);
1056 } /* Channel_LogServer */
1060 Channel_CheckKey(CHANNEL *Chan, CLIENT *Client, const char *Key)
1062 char *file_name, line[COMMAND_LEN], *nick, *pass;
1065 assert(Chan != NULL);
1066 assert(Client != NULL);
1067 assert(Key != NULL);
1069 if (!strchr(Chan->modes, 'k'))
1071 if (strcmp(Chan->key, Key) == 0)
1076 file_name = array_start(&Chan->keyfile);
1079 fd = fopen(file_name, "r");
1081 Log(LOG_ERR, "Can't open channel key file \"%s\" for %s: %s",
1082 file_name, Chan->name, strerror(errno));
1086 while (fgets(line, (int)sizeof(line), fd) != NULL) {
1088 if (! (nick = strchr(line, ':')))
1091 if (!Match(line, Client_User(Client)))
1093 if (! (pass = strchr(nick, ':')))
1096 if (!Match(nick, Client_ID(Client)))
1098 if (strcmp(Key, pass) != 0)
1106 } /* Channel_CheckKey */
1110 Get_First_Cl2Chan( CLIENT *Client, CHANNEL *Chan )
1112 return Get_Next_Cl2Chan( My_Cl2Chan, Client, Chan );
1113 } /* Get_First_Cl2Chan */
1117 Get_Next_Cl2Chan( CL2CHAN *Start, CLIENT *Client, CHANNEL *Channel )
1121 assert( Client != NULL || Channel != NULL );
1126 if(( Client ) && ( cl2chan->client == Client )) return cl2chan;
1127 if(( Channel ) && ( cl2chan->channel == Channel )) return cl2chan;
1128 cl2chan = cl2chan->next;
1131 } /* Get_Next_Cl2Chan */
1135 * Remove a channel and free all of its data structures.
1138 Delete_Channel(CHANNEL *Chan)
1140 CHANNEL *chan, *last_chan;
1151 assert(chan != NULL);
1155 /* maintain channel list */
1157 last_chan->next = chan->next;
1159 My_Channels = chan->next;
1161 LogDebug("Freed channel structure for \"%s\".", Chan->name);
1163 } /* Delete_Channel */
1167 Set_KeyFile(CHANNEL *Chan, const char *KeyFile)
1171 assert(Chan != NULL);
1172 assert(KeyFile != NULL);
1174 len = strlen(KeyFile);
1175 if (len < array_bytes(&Chan->keyfile)) {
1176 Log(LOG_INFO, "Channel key file of %s removed.", Chan->name);
1177 array_free(&Chan->keyfile);
1183 if (!array_copyb(&Chan->keyfile, KeyFile, len+1))
1185 "Could not set new channel key file \"%s\" for %s: %s",
1186 KeyFile, Chan->name, strerror(errno));
1188 Log(LOG_INFO|LOG_snotice,
1189 "New local channel key file \"%s\" for %s activated.",
1190 KeyFile, Chan->name);