ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/userhost.c
Revision: 8385
Committed: Fri Mar 16 20:09:55 2018 UTC (8 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 3201 byte(s)
Log Message:
- Rip out mempool

File Contents

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

Properties

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