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

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2003-2018 ircd-hybrid development team
5 *
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 #include "memory.h"
33
34
35 /* userhost_count()
36 *
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 userhost_count(const char *host, unsigned int *global_p, unsigned int *local_p)
48 {
49 struct UserHost *userhost;
50
51 if ((userhost = hash_find_userhost(host)) == NULL)
52 return;
53
54 if (global_p)
55 *global_p = userhost->gcount;
56 if (local_p)
57 *local_p = userhost->lcount;
58 }
59
60 /* userhost_find_or_add()
61 *
62 * inputs - host name
63 * output - none
64 * side effects - find UserHost * for given host name
65 */
66 static struct UserHost *
67 userhost_find_or_add(const char *host)
68 {
69 struct UserHost *userhost;
70
71 if ((userhost = hash_find_userhost(host)))
72 return userhost;
73
74 userhost = xcalloc(sizeof(*userhost));
75
76 strlcpy(userhost->host, host, sizeof(userhost->host));
77 hash_add_userhost(userhost);
78
79 return userhost;
80 }
81
82 /* userhost_add()
83 *
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 userhost_add(const char *host, int global)
92 {
93 struct UserHost *userhost;
94
95 if ((userhost = userhost_find_or_add(host)) == NULL)
96 return;
97
98 userhost->gcount++;
99
100 if (!global)
101 userhost->lcount++;
102 }
103
104 /* userhost_del()
105 *
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 userhost_del(const char *host, int global)
114 {
115 struct UserHost *userhost;
116
117 if ((userhost = hash_find_userhost(host)) == NULL)
118 return;
119
120 if (userhost->gcount > 0)
121 userhost->gcount--;
122
123 if (!global)
124 if (userhost->lcount > 0)
125 userhost->lcount--;
126
127 if (userhost->gcount == 0 && userhost->lcount == 0)
128 {
129 hash_del_userhost(userhost);
130 xfree(userhost);
131 }
132 }

Properties

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