ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/userhost.c
Revision: 7924
Committed: Sat Dec 31 13:57:08 2016 UTC (9 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 3357 byte(s)
Log Message:
- Update copyright years

File Contents

# User Rev Content
1 michael 6393 /*
2     * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3     *
4 michael 7924 * Copyright (c) 2003-2017 ircd-hybrid development team
5 michael 6393 *
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 userhost.c
23     * \brief Global user limits.
24     * \version $Id$
25     */
26    
27     #include "list.h"
28     #include "hash.h"
29     #include "client.h"
30     #include "userhost.h"
31     #include "mempool.h"
32     #include "irc_string.h"
33    
34    
35     static mp_pool_t *userhost_pool;
36    
37    
38     void
39     userhost_init(void)
40     {
41     userhost_pool = mp_pool_new(sizeof(struct UserHost), MP_CHUNK_SIZE_USERHOST);
42     }
43    
44 michael 6441 /* userhost_count()
45 michael 6393 *
46     * inputs - user name
47     * - hostname
48     * - int flag 1 if global, 0 if local
49     * - pointer to where global count should go
50     * - pointer to where local count should go
51     * - pointer to where identd count should go (local clients only)
52     * output - none
53     * side effects -
54     */
55     void
56 michael 7624 userhost_count(const char *host, unsigned int *global_p, unsigned int *local_p)
57 michael 6393 {
58 michael 7624 struct UserHost *userhost;
59 michael 6393
60 michael 7624 if ((userhost = hash_find_userhost(host)) == NULL)
61 michael 6393 return;
62    
63 michael 7624 if (global_p)
64     *global_p = userhost->gcount;
65     if (local_p)
66     *local_p = userhost->lcount;
67 michael 6393 }
68    
69 michael 6441 /* userhost_find_or_add()
70 michael 6393 *
71     * inputs - host name
72     * output - none
73     * side effects - find UserHost * for given host name
74     */
75     static struct UserHost *
76 michael 6441 userhost_find_or_add(const char *host)
77 michael 6393 {
78 michael 7624 struct UserHost *userhost;
79 michael 6393
80     if ((userhost = hash_find_userhost(host)))
81     return userhost;
82    
83     userhost = mp_pool_get(userhost_pool);
84    
85     strlcpy(userhost->host, host, sizeof(userhost->host));
86     hash_add_userhost(userhost);
87    
88     return userhost;
89     }
90    
91 michael 6441 /* userhost_add()
92 michael 6393 *
93     * inputs - user name
94     * - hostname
95     * - int flag 1 if global, 0 if local
96     * output - none
97     * side effects - add given user@host to hash tables
98     */
99     void
100 michael 7624 userhost_add(const char *host, int global)
101 michael 6393 {
102 michael 7624 struct UserHost *userhost;
103 michael 6393
104 michael 7624 if ((userhost = userhost_find_or_add(host)) == NULL)
105 michael 6393 return;
106    
107 michael 7624 userhost->gcount++;
108 michael 6393
109     if (!global)
110 michael 7624 userhost->lcount++;
111 michael 6393 }
112    
113 michael 6441 /* userhost_del()
114 michael 6393 *
115     * inputs - user name
116     * - hostname
117     * - int flag 1 if global, 0 if local
118     * output - none
119     * side effects - delete given user@host to hash tables
120     */
121     void
122 michael 7624 userhost_del(const char *host, int global)
123 michael 6393 {
124 michael 7624 struct UserHost *userhost;
125 michael 6393
126 michael 7624 if ((userhost = hash_find_userhost(host)) == NULL)
127 michael 6393 return;
128    
129 michael 7624 if (userhost->gcount > 0)
130     userhost->gcount--;
131 michael 6393
132 michael 7624 if (!global)
133     if (userhost->lcount > 0)
134     userhost->lcount--;
135 michael 6393
136 michael 7624 if (userhost->gcount == 0 && userhost->lcount == 0)
137     {
138     hash_del_userhost(userhost);
139     mp_pool_release(userhost);
140 michael 6393 }
141     }

Properties

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