ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_invite.c
Revision: 9857
Committed: Fri Jan 1 04:43:22 2021 UTC (5 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 3651 byte(s)
Log Message:
- Bump copyright years

File Contents

# User Rev Content
1 michael 9265 /*
2     * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3     *
4 michael 9857 * Copyright (c) 1997-2021 ircd-hybrid development team
5 michael 9265 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19     * USA
20     */
21    
22     /*! \file channel_invite.c
23     * \brief Channel invitation related functions
24 michael 9271 * \version $Id$
25 michael 9265 */
26    
27     #include "stdinc.h"
28     #include "memory.h"
29     #include "list.h"
30     #include "event.h"
31     #include "channel.h"
32     #include "channel_invite.h"
33     #include "conf.h"
34    
35    
36 michael 9354 /*! \brief Checks whether a client is invited to a certain channel. While walking the
37     * shortest invitation list, expired invitations are vaccumed automatically.
38     * \param channel Pointer to channel block
39     * \param client Pointer to client
40     * \return A struct Invite pointer or NULL
41     */
42 michael 9265 struct Invite *
43     invite_find(struct Channel *channel, struct Client *client)
44     {
45     dlink_node *node, *node_next;
46     dlink_list *list;
47    
48     /* Take the shortest of the two lists */
49     if (dlink_list_length(&client->connection->invited) < dlink_list_length(&channel->invites))
50     list = &client->connection->invited;
51     else
52     list = &channel->invites;
53    
54     DLINK_FOREACH_SAFE(node, node_next, list->head)
55     {
56     struct Invite *invite = node->data;
57    
58     if (ConfigChannel.invite_expire_time &&
59     ConfigChannel.invite_expire_time + invite->when < event_base->time.sec_monotonic)
60     invite_del(invite);
61     else if (invite->channel == channel && invite->client == client)
62     return invite;
63     }
64    
65     return NULL;
66     }
67    
68     /*! \brief Adds client to invite list
69     * \param channel Pointer to channel block
70     * \param client Pointer to client to add invite to
71     */
72     void
73     invite_add(struct Channel *channel, struct Client *client)
74     {
75     struct Invite *invite = invite_find(channel, client);
76     if (invite)
77     invite_del(invite);
78    
79     invite = xcalloc(sizeof(*invite));
80     invite->client = client;
81     invite->channel = channel;
82     invite->when = event_base->time.sec_monotonic;
83    
84     /* Delete last link in chain if the list is max length */
85     while (dlink_list_length(&client->connection->invited) &&
86     dlink_list_length(&client->connection->invited) >= ConfigChannel.max_invites)
87     invite_del(client->connection->invited.tail->data);
88    
89     /* Add client to channel invite list */
90     dlinkAdd(invite, &invite->chan_node, &channel->invites);
91    
92     /* Add channel to the end of the client invite list */
93     dlinkAdd(invite, &invite->user_node, &client->connection->invited);
94     }
95    
96     /*! \brief Delete Invite block from channel invite list
97     * and client invite list
98     * \param invite Pointer to Invite struct
99     */
100     void
101     invite_del(struct Invite *invite)
102     {
103     dlinkDelete(&invite->user_node, &invite->client->connection->invited);
104     dlinkDelete(&invite->chan_node, &invite->channel->invites);
105    
106     /* Release memory pointed to by 'invite' */
107     xfree(invite);
108     }
109    
110     /*! \brief Removes and frees all Invite blocks from a list
111     * \param list Pointer to a dlink_list
112     */
113     void
114     invite_clear_list(dlink_list *list)
115     {
116     while (list->head)
117     invite_del(list->head->data);
118     }

Properties

Name Value
svn:eol-style native
svn:keywords Id