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 Update_Predefined PARAMS((CHANNEL *Chan,
65 const struct Conf_Channel *Conf_Chan));
66 static void Set_Key_File PARAMS((CHANNEL *Chan, FILE *KeyFile));
77 sc = Channel_Create("&SERVER");
79 Channel_SetModes(sc, "mnPt");
80 Channel_SetTopic(sc, Client_ThisServer(), "Server Messages");
85 GLOBAL struct list_head *
86 Channel_GetListBans(CHANNEL *c)
93 GLOBAL struct list_head *
94 Channel_GetListInvites(CHANNEL *c)
97 return &c->list_invites;
102 Channel_InitPredefined( void )
104 /* Generate predefined persistent channels */
107 const struct Conf_Channel *conf_chan;
109 size_t i, channel_count = array_length(&Conf_Channels, sizeof(*conf_chan));
111 conf_chan = array_start(&Conf_Channels);
113 assert(channel_count == 0 || conf_chan != NULL);
115 for (i = 0; i < channel_count; i++, conf_chan++) {
116 if (!conf_chan->name[0] || !Channel_IsValidName(conf_chan->name)) {
117 Log(LOG_ERR, "Can't create pre-defined channel: invalid name: \"%s\"",
122 new_chan = Channel_Search(conf_chan->name);
125 "Can't create pre-defined channel \"%s\": name already in use.",
127 Update_Predefined(new_chan, conf_chan);
131 new_chan = Channel_Create(conf_chan->name);
133 Log(LOG_ERR, "Can't create pre-defined channel \"%s\"",
137 Log(LOG_INFO, "Created pre-defined channel \"%s\"",
140 Channel_ModeAdd(new_chan, 'P');
142 if (conf_chan->topic[0])
143 Channel_SetTopic(new_chan, NULL, conf_chan->topic);
145 c = conf_chan->modes;
147 Channel_ModeAdd(new_chan, *c++);
149 Channel_SetKey(new_chan, conf_chan->key);
150 Channel_SetMaxUsers(new_chan, conf_chan->maxusers);
151 Update_Predefined(new_chan, conf_chan);
154 array_free(&Conf_Channels);
155 } /* Channel_InitPredefined */
159 Free_Channel(CHANNEL *chan)
161 array_free(&chan->topic);
162 Lists_Free(&chan->list_bans);
163 Lists_Free(&chan->list_invites);
165 fclose(Chan->keyfile);
175 CL2CHAN *cl2chan, *cl2chan_next;
177 /* free struct Channel */
185 /* Free Channel allocation table */
186 cl2chan = My_Cl2Chan;
188 cl2chan_next = cl2chan->next;
190 cl2chan = cl2chan_next;
197 * This function lets a client join a channel. First, the function
198 * checks that the specified channel name is valid and that the client
199 * isn't already a member. If the specified channel doesn't exist,
200 * a new channel is created. Client is added to channel by function
204 Channel_Join( CLIENT *Client, char *Name )
208 assert(Client != NULL);
209 assert(Name != NULL);
211 /* Check that the channel name is valid */
212 if (! Channel_IsValidName(Name)) {
213 IRC_WriteStrClient(Client, ERR_NOSUCHCHANNEL_MSG,
214 Client_ID(Client), Name);
218 chan = Channel_Search(Name);
220 /* Check if the client is already in the channel */
221 if (Get_Cl2Chan(chan, Client))
224 /* If the specified channel does not exist, the channel
226 chan = Channel_Create(Name);
231 /* Add user to Channel */
232 if (! Add_Client(chan, Client))
240 * Part client from channel.
241 * This function lets a client part from a channel. First, the function checks
242 * if the channel exists and the client is a member of it and sends out
243 * appropriate error messages if not. The real work is done by the function
247 Channel_Part(CLIENT * Client, CLIENT * Origin, const char *Name, const char *Reason)
251 assert(Client != NULL);
252 assert(Name != NULL);
253 assert(Reason != NULL);
255 /* Check that specified channel exists */
256 chan = Channel_Search(Name);
258 IRC_WriteStrClient(Client, ERR_NOSUCHCHANNEL_MSG,
259 Client_ID(Client), Name);
263 /* Check that the client is in the channel */
264 if (!Get_Cl2Chan(chan, Client)) {
265 IRC_WriteStrClient(Client, ERR_NOTONCHANNEL_MSG,
266 Client_ID(Client), Name);
270 /* Part client from channel */
271 if (!Remove_Client(REMOVE_PART, chan, Client, Origin, Reason, true))
279 * Kick user from Channel
282 Channel_Kick(CLIENT *Peer, CLIENT *Target, CLIENT *Origin, const char *Name,
287 assert(Peer != NULL);
288 assert(Target != NULL);
289 assert(Origin != NULL);
290 assert(Name != NULL);
291 assert(Reason != NULL);
293 /* Check that channel exists */
294 chan = Channel_Search( Name );
297 IRC_WriteStrClient( Origin, ERR_NOSUCHCHANNEL_MSG, Client_ID( Origin ), Name );
301 if (Client_Type(Peer) != CLIENT_SERVER &&
302 Client_Type(Origin) != CLIENT_SERVICE) {
303 /* Check that user is on the specified channel */
304 if (!Channel_IsMemberOf(chan, Origin)) {
305 IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG,
306 Client_ID(Origin), Name);
310 /* Check if user has operator status */
311 if (!strchr(Channel_UserModes(chan, Origin), 'o')) {
312 IRC_WriteStrClient(Origin, ERR_CHANOPRIVSNEEDED_MSG,
313 Client_ID(Origin), Name);
318 /* Check that the client to be kicked is on the specified channel */
319 if (!Channel_IsMemberOf(chan, Target)) {
320 IRC_WriteStrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
321 Client_ID(Origin), Client_ID(Target), Name );
325 /* Kick Client from channel */
326 Remove_Client( REMOVE_KICK, chan, Target, Origin, Reason, true);
331 Channel_Quit( CLIENT *Client, char *Reason )
335 assert( Client != NULL );
336 assert( Reason != NULL );
338 IRC_WriteStrRelatedPrefix( Client, Client, false, "QUIT :%s", Reason );
344 Remove_Client( REMOVE_QUIT, c, Client, Client, Reason, false );
351 Channel_Count( void )
354 unsigned long count = 0;
363 } /* Channel_Count */
367 Channel_MemberCount( CHANNEL *Chan )
370 unsigned long count = 0;
372 assert( Chan != NULL );
374 cl2chan = My_Cl2Chan;
377 if( cl2chan->channel == Chan ) count++;
378 cl2chan = cl2chan->next;
381 } /* Channel_MemberCount */
385 Channel_CountForUser( CLIENT *Client )
387 /* Count number of channels a user is member of. */
392 assert( Client != NULL );
394 cl2chan = My_Cl2Chan;
397 if( cl2chan->client == Client ) count++;
398 cl2chan = cl2chan->next;
402 } /* Channel_CountForUser */
406 Channel_Name( const CHANNEL *Chan )
408 assert( Chan != NULL );
414 Channel_Modes( CHANNEL *Chan )
416 assert( Chan != NULL );
418 } /* Channel_Modes */
422 Channel_Key( CHANNEL *Chan )
424 assert( Chan != NULL );
430 Channel_MaxUsers( CHANNEL *Chan )
432 assert( Chan != NULL );
433 return Chan->maxusers;
434 } /* Channel_MaxUsers */
438 Channel_First( void )
441 } /* Channel_First */
445 Channel_Next( CHANNEL *Chan )
447 assert( Chan != NULL );
453 Channel_Search( const char *Name )
455 /* Search channel structure */
460 assert( Name != NULL );
462 search_hash = Hash( Name );
466 if( search_hash == c->hash )
469 if( strcasecmp( Name, c->name ) == 0 ) return c;
474 } /* Channel_Search */
478 Channel_FirstMember( CHANNEL *Chan )
480 assert( Chan != NULL );
481 return Get_First_Cl2Chan( NULL, Chan );
482 } /* Channel_FirstMember */
486 Channel_NextMember( CHANNEL *Chan, CL2CHAN *Cl2Chan )
488 assert( Chan != NULL );
489 assert( Cl2Chan != NULL );
490 return Get_Next_Cl2Chan( Cl2Chan->next, NULL, Chan );
491 } /* Channel_NextMember */
495 Channel_FirstChannelOf( CLIENT *Client )
497 assert( Client != NULL );
498 return Get_First_Cl2Chan( Client, NULL );
499 } /* Channel_FirstChannelOf */
503 Channel_NextChannelOf( CLIENT *Client, CL2CHAN *Cl2Chan )
505 assert( Client != NULL );
506 assert( Cl2Chan != NULL );
507 return Get_Next_Cl2Chan( Cl2Chan->next, Client, NULL );
508 } /* Channel_NextChannelOf */
512 Channel_GetClient( CL2CHAN *Cl2Chan )
514 assert( Cl2Chan != NULL );
515 return Cl2Chan->client;
516 } /* Channel_GetClient */
520 Channel_GetChannel( CL2CHAN *Cl2Chan )
522 assert( Cl2Chan != NULL );
523 return Cl2Chan->channel;
524 } /* Channel_GetChannel */
528 Channel_IsValidName( const char *Name )
530 assert( Name != NULL );
533 if (strlen(Name) <= 1)
536 if (strchr("#&+", Name[0]) == NULL)
538 if (strlen(Name) >= CHANNEL_NAME_LEN)
541 return Name[strcspn(Name, " ,:\007")] == 0;
542 } /* Channel_IsValidName */
546 Channel_ModeAdd( CHANNEL *Chan, char Mode )
549 * If the channel already had this mode, return false.
550 * If the channel mode was newly set return true.
555 assert( Chan != NULL );
557 x[0] = Mode; x[1] = '\0';
558 if( ! strchr( Chan->modes, x[0] ))
560 /* Channel does not have this mode yet, set it */
561 strlcat( Chan->modes, x, sizeof( Chan->modes ));
565 } /* Channel_ModeAdd */
569 Channel_ModeDel( CHANNEL *Chan, char Mode )
572 * if the mode was removed return true.
573 * if the channel did not have the mode, return false.
577 assert( Chan != NULL );
579 p = strchr( Chan->modes, Mode );
580 if( ! p ) return false;
582 /* Channel has mode -> delete */
589 } /* Channel_ModeDel */
593 Channel_UserModeAdd( CHANNEL *Chan, CLIENT *Client, char Mode )
595 /* Set Channel-User-Mode.
596 * if mode was newly set, return true.
597 * if the User already had this channel-mode, return false.
603 assert( Chan != NULL );
604 assert( Client != NULL );
606 cl2chan = Get_Cl2Chan( Chan, Client );
607 assert( cl2chan != NULL );
609 x[0] = Mode; x[1] = '\0';
610 if( ! strchr( cl2chan->modes, x[0] ))
612 /* mode not set, -> set it */
613 strlcat( cl2chan->modes, x, sizeof( cl2chan->modes ));
617 } /* Channel_UserModeAdd */
621 Channel_UserModeDel( CHANNEL *Chan, CLIENT *Client, char Mode )
623 /* Delete Channel-User-Mode.
624 * If Mode was removed, return true.
625 * If User did not have the Channel-Mode, return false.
631 assert( Chan != NULL );
632 assert( Client != NULL );
634 cl2chan = Get_Cl2Chan( Chan, Client );
635 assert( cl2chan != NULL );
637 p = strchr( cl2chan->modes, Mode );
638 if( ! p ) return false;
640 /* Client has Mode -> delete */
647 } /* Channel_UserModeDel */
651 Channel_UserModes( CHANNEL *Chan, CLIENT *Client )
653 /* return Users' Channel-Modes */
657 assert( Chan != NULL );
658 assert( Client != NULL );
660 cl2chan = Get_Cl2Chan( Chan, Client );
661 assert( cl2chan != NULL );
663 return cl2chan->modes;
664 } /* Channel_UserModes */
668 Channel_IsMemberOf( CHANNEL *Chan, CLIENT *Client )
670 /* Test if Client is on Channel Chan */
672 assert( Chan != NULL );
673 assert( Client != NULL );
674 return Get_Cl2Chan(Chan, Client) != NULL;
675 } /* Channel_IsMemberOf */
679 Channel_Topic( CHANNEL *Chan )
682 assert( Chan != NULL );
683 ret = array_start(&Chan->topic);
684 return ret ? ret : "";
685 } /* Channel_Topic */
691 Channel_TopicTime(CHANNEL *Chan)
693 assert(Chan != NULL);
694 return (unsigned int) Chan->topic_time;
695 } /* Channel_TopicTime */
699 Channel_TopicWho(CHANNEL *Chan)
701 assert(Chan != NULL);
702 return Chan->topic_who;
703 } /* Channel_TopicWho */
709 Channel_SetTopic(CHANNEL *Chan, CLIENT *Client, const char *Topic)
712 assert( Chan != NULL );
713 assert( Topic != NULL );
716 if (len < array_bytes(&Chan->topic))
717 array_free(&Chan->topic);
719 if (len >= COMMAND_LEN || !array_copyb(&Chan->topic, Topic, len+1))
720 Log(LOG_WARNING, "could not set new Topic \"%s\" on %s: %s",
721 Topic, Chan->name, strerror(errno));
723 Chan->topic_time = time(NULL);
724 if (Client != NULL && Client_Type(Client) != CLIENT_SERVER)
725 strlcpy(Chan->topic_who, Client_ID(Client),
726 sizeof Chan->topic_who);
728 strlcpy(Chan->topic_who, DEFAULT_TOPIC_ID,
729 sizeof Chan->topic_who);
733 } /* Channel_SetTopic */
737 Channel_SetModes( CHANNEL *Chan, char *Modes )
739 assert( Chan != NULL );
740 assert( Modes != NULL );
742 strlcpy( Chan->modes, Modes, sizeof( Chan->modes ));
743 } /* Channel_SetModes */
747 Channel_SetKey( CHANNEL *Chan, const char *Key )
749 assert( Chan != NULL );
750 assert( Key != NULL );
752 strlcpy( Chan->key, Key, sizeof( Chan->key ));
753 LogDebug("Channel %s: Key is now \"%s\".", Chan->name, Chan->key );
754 } /* Channel_SetKey */
758 Channel_SetMaxUsers(CHANNEL *Chan, unsigned long Count)
760 assert( Chan != NULL );
762 Chan->maxusers = Count;
763 LogDebug("Channel %s: Member limit is now %lu.", Chan->name, Chan->maxusers );
764 } /* Channel_SetMaxUsers */
768 Can_Send_To_Channel(CHANNEL *Chan, CLIENT *From)
770 bool is_member, has_voice, is_op;
772 is_member = has_voice = is_op = false;
774 /* The server itself always can send messages :-) */
775 if (Client_ThisServer() == From)
778 if (Channel_IsMemberOf(Chan, From)) {
780 if (strchr(Channel_UserModes(Chan, From), 'v'))
782 if (strchr(Channel_UserModes(Chan, From), 'o'))
787 * Is the client allowed to write to channel?
789 * If channel mode n set: non-members cannot send to channel.
790 * If channel mode m set: need voice.
792 if (strchr(Channel_Modes(Chan), 'n') && !is_member)
795 if (is_op || has_voice)
798 if (strchr(Channel_Modes(Chan), 'm'))
801 return !Lists_Check(&Chan->list_bans, From);
806 Channel_Write(CHANNEL *Chan, CLIENT *From, CLIENT *Client, const char *Command,
807 bool SendErrors, const char *Text)
809 if (!Can_Send_To_Channel(Chan, From)) {
811 return CONNECTED; /* no error, see RFC 2812 */
812 return IRC_WriteStrClient(From, ERR_CANNOTSENDTOCHAN_MSG,
813 Client_ID(From), Channel_Name(Chan));
816 if (Client_Conn(From) > NONE)
817 Conn_UpdateIdle(Client_Conn(From));
819 return IRC_WriteStrChannelPrefix(Client, Chan, From, true,
820 "%s %s :%s", Command, Channel_Name(Chan), Text);
825 Channel_Create( const char *Name )
827 /* Create new CHANNEL structure and add it to linked list */
830 assert( Name != NULL );
832 c = (CHANNEL *)malloc( sizeof( CHANNEL ));
835 Log( LOG_EMERG, "Can't allocate memory! [New_Chan]" );
838 memset( c, 0, sizeof( CHANNEL ));
839 strlcpy( c->name, Name, sizeof( c->name ));
840 c->hash = Hash( c->name );
841 c->next = My_Channels;
843 LogDebug("Created new channel structure for \"%s\".", Name);
845 } /* Channel_Create */
849 Get_Cl2Chan( CHANNEL *Chan, CLIENT *Client )
853 assert( Chan != NULL );
854 assert( Client != NULL );
856 cl2chan = My_Cl2Chan;
859 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) return cl2chan;
860 cl2chan = cl2chan->next;
867 Add_Client( CHANNEL *Chan, CLIENT *Client )
871 assert( Chan != NULL );
872 assert( Client != NULL );
874 /* Create new CL2CHAN structure */
875 cl2chan = (CL2CHAN *)malloc( sizeof( CL2CHAN ));
878 Log( LOG_EMERG, "Can't allocate memory! [Add_Client]" );
881 cl2chan->channel = Chan;
882 cl2chan->client = Client;
883 strcpy( cl2chan->modes, "" );
886 cl2chan->next = My_Cl2Chan;
887 My_Cl2Chan = cl2chan;
889 LogDebug("User \"%s\" joined channel \"%s\".", Client_Mask(Client), Chan->name);
896 Remove_Client( int Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, const char *Reason, bool InformServer )
898 CL2CHAN *cl2chan, *last_cl2chan;
901 assert( Chan != NULL );
902 assert( Client != NULL );
903 assert( Origin != NULL );
904 assert( Reason != NULL );
906 /* Do not inform other servers if the channel is local to this server,
907 * regardless of what the caller requested! */
909 InformServer = !Channel_IsLocal(Chan);
912 cl2chan = My_Cl2Chan;
915 if(( cl2chan->channel == Chan ) && ( cl2chan->client == Client )) break;
916 last_cl2chan = cl2chan;
917 cl2chan = cl2chan->next;
919 if( ! cl2chan ) return false;
921 c = cl2chan->channel;
924 /* maintain cl2chan list */
925 if( last_cl2chan ) last_cl2chan->next = cl2chan->next;
926 else My_Cl2Chan = cl2chan->next;
932 /* QUIT: other servers have already been notified,
933 * see Client_Destroy(); so only inform other clients
934 * in same channel. */
935 assert( InformServer == false );
936 LogDebug("User \"%s\" left channel \"%s\" (%s).",
937 Client_Mask( Client ), c->name, Reason );
940 /* User was KICKed: inform other servers (public
941 * channels) and all users in the channel */
943 IRC_WriteStrServersPrefix( Client_NextHop( Origin ),
944 Origin, "KICK %s %s :%s", c->name, Client_ID( Client ), Reason);
945 IRC_WriteStrChannelPrefix(Client, c, Origin, false, "KICK %s %s :%s",
946 c->name, Client_ID( Client ), Reason );
947 if ((Client_Conn(Client) > NONE) &&
948 (Client_Type(Client) == CLIENT_USER))
950 IRC_WriteStrClientPrefix(Client, Origin, "KICK %s %s :%s",
951 c->name, Client_ID( Client ), Reason);
953 LogDebug("User \"%s\" has been kicked off \"%s\" by \"%s\": %s.",
954 Client_Mask( Client ), c->name, Client_ID(Origin), Reason);
958 IRC_WriteStrServersPrefix(Origin, Client, "PART %s :%s", c->name, Reason);
960 IRC_WriteStrChannelPrefix(Origin, c, Client, false, "PART %s :%s",
963 if ((Client_Conn(Origin) > NONE) &&
964 (Client_Type(Origin) == CLIENT_USER))
966 IRC_WriteStrClientPrefix( Origin, Client, "PART %s :%s", c->name, Reason);
967 LogDebug("User \"%s\" left channel \"%s\" (%s).",
968 Client_Mask(Client), c->name, Reason);
972 /* When channel is empty and is not pre-defined, delete */
973 if( ! strchr( Channel_Modes( Chan ), 'P' ))
975 if( ! Get_First_Cl2Chan( NULL, Chan )) Delete_Channel( Chan );
979 } /* Remove_Client */
983 Channel_AddBan(CHANNEL *c, const char *mask )
985 struct list_head *h = Channel_GetListBans(c);
986 return Lists_Add(h, mask, false);
991 Channel_AddInvite(CHANNEL *c, const char *mask, bool onlyonce)
993 struct list_head *h = Channel_GetListInvites(c);
994 return Lists_Add(h, mask, onlyonce);
999 ShowInvitesBans(struct list_head *head, CLIENT *Client, CHANNEL *Channel, bool invite)
1001 struct list_elem *e;
1002 char *msg = invite ? RPL_INVITELIST_MSG : RPL_BANLIST_MSG;
1005 assert( Client != NULL );
1006 assert( Channel != NULL );
1008 e = Lists_GetFirst(head);
1010 if( ! IRC_WriteStrClient( Client, msg, Client_ID( Client ),
1011 Channel_Name( Channel ), Lists_GetMask(e) )) return DISCONNECTED;
1012 e = Lists_GetNext(e);
1015 msg_end = invite ? RPL_ENDOFINVITELIST_MSG : RPL_ENDOFBANLIST_MSG;
1016 return IRC_WriteStrClient( Client, msg_end, Client_ID( Client ), Channel_Name( Channel ));
1021 Channel_ShowBans( CLIENT *Client, CHANNEL *Channel )
1023 struct list_head *h;
1025 assert( Channel != NULL );
1027 h = Channel_GetListBans(Channel);
1028 return ShowInvitesBans(h, Client, Channel, false);
1033 Channel_ShowInvites( CLIENT *Client, CHANNEL *Channel )
1035 struct list_head *h;
1037 assert( Channel != NULL );
1039 h = Channel_GetListInvites(Channel);
1040 return ShowInvitesBans(h, Client, Channel, true);
1045 * Log a message to the local &SERVER channel, if it exists.
1048 Channel_LogServer(char *msg)
1053 assert(msg != NULL);
1055 sc = Channel_Search("&SERVER");
1059 c = Client_ThisServer();
1060 Channel_Write(sc, c, c, "PRIVMSG", false, msg);
1061 } /* Channel_LogServer */
1065 Channel_CheckKey(CHANNEL *Chan, CLIENT *Client, const char *Key)
1067 char line[COMMAND_LEN], *nick, *pass;
1069 assert(Chan != NULL);
1070 assert(Client != NULL);
1071 assert(Key != NULL);
1073 if (!strchr(Chan->modes, 'k'))
1075 if (strcmp(Chan->key, Key) == 0)
1080 Chan->keyfile = freopen(NULL, "r", Chan->keyfile);
1081 while (fgets(line, sizeof(line), Chan->keyfile) != NULL) {
1083 if (! (nick = strchr(line, ':')))
1086 if (!Match(line, Client_User(Client)))
1088 if (! (pass = strchr(nick, ':')))
1091 if (!Match(nick, Client_ID(Client)))
1093 if (strcmp(Key, pass) != 0)
1099 } /* Channel_CheckKey */
1103 Get_First_Cl2Chan( CLIENT *Client, CHANNEL *Chan )
1105 return Get_Next_Cl2Chan( My_Cl2Chan, Client, Chan );
1106 } /* Get_First_Cl2Chan */
1110 Get_Next_Cl2Chan( CL2CHAN *Start, CLIENT *Client, CHANNEL *Channel )
1114 assert( Client != NULL || Channel != NULL );
1119 if(( Client ) && ( cl2chan->client == Client )) return cl2chan;
1120 if(( Channel ) && ( cl2chan->channel == Channel )) return cl2chan;
1121 cl2chan = cl2chan->next;
1124 } /* Get_Next_Cl2Chan */
1128 * Remove a channel and free all of its data structures.
1131 Delete_Channel(CHANNEL *Chan)
1133 CHANNEL *chan, *last_chan;
1144 assert(chan != NULL);
1148 /* maintain channel list */
1150 last_chan->next = chan->next;
1152 My_Channels = chan->next;
1154 LogDebug("Freed channel structure for \"%s\".", Chan->name);
1156 } /* Delete_Channel */
1160 Update_Predefined(CHANNEL *Chan, const struct Conf_Channel *Conf_Chan)
1164 if (! Conf_Chan->keyfile || ! *Conf_Chan->keyfile)
1167 fd = fopen(Conf_Chan->keyfile, "r");
1170 "Can't open channel key file for \"%s\", \"%s\": %s",
1171 Conf_Chan->name, Conf_Chan->keyfile,
1174 Set_Key_File(Chan, fd);
1175 } /* Update_Predefined */
1179 Set_Key_File(CHANNEL *Chan, FILE *KeyFile)
1181 assert(Chan != NULL);
1184 fclose(Chan->keyfile);
1185 Chan->keyfile = KeyFile;
1186 Log(LOG_INFO|LOG_snotice,
1187 "New local channel key file for \"%s\" activated.", Chan->name);
1188 } /* Set_Key_File */