#include "s_user.h"
-static mp_pool_t *userhost_pool = NULL;
-
static unsigned int hashf_xor_key = 0;
/* The actual hash tables, They MUST be of the same HASHSIZE, variable
void
hash_init(void)
{
- userhost_pool = mp_pool_new("userhost", sizeof(struct UserHost), MP_CHUNK_SIZE_USERHOST);
-
hashf_xor_key = genrand_int32();
}
return userhost;
}
-/* count_user_host()
- *
- * inputs
- * - hostname
- * - pointer to where global count should go
- * - pointer to where local count should go
- * output - none
- * side effects -
- */
-void
-count_user_host(const char *host, unsigned int *global_p, unsigned int *local_p)
-{
- struct UserHost *userhost = hash_find_userhost(host);
-
- if (userhost == NULL)
- return;
-
- if (global_p != NULL)
- *global_p = userhost->gcount;
- if (local_p != NULL)
- *local_p = userhost->lcount;
-}
-
-/* find_or_add_userhost()
- *
- * inputs - host name
- * output - none
- * side effects - find UserHost * for given host name
- */
-static struct UserHost *
-find_or_add_userhost(const char *host)
-{
- struct UserHost *userhost = hash_find_userhost(host);
-
- if (userhost != NULL)
- return userhost;
-
- userhost = mp_pool_get(userhost_pool);
-
- memset(userhost, 0, sizeof(*userhost));
- strlcpy(userhost->host, host, sizeof(userhost->host));
- hash_add_userhost(userhost);
-
- return userhost;
-}
-
-/* add_user_host()
- *
- * inputs
- * - hostname
- * - int flag 1 if global, 0 if local
- * output - none
- * side effects - add given user@host to hash tables
- */
-void
-add_user_host(const char *host, int global)
-{
- struct UserHost *userhost = find_or_add_userhost(host);
-
- if (userhost == NULL)
- return;
-
- ++userhost->gcount;
-
- if (!global)
- {
- ++userhost->lcount;
- }
-}
-
-/* delete_user_host()
- *
- * inputs
- * - hostname
- * - int flag 1 if global, 0 if local
- * output - none
- * side effects - delete given user@host to hash tables
- */
-void
-delete_user_host(const char *host, int global)
-{
- struct UserHost *userhost = hash_find_userhost(host);
-
- if (userhost == NULL)
- return;
-
- if (userhost->gcount > 0)
- --userhost->gcount;
-
- if (!global)
- if (userhost->lcount > 0)
- --userhost->lcount;
-
- if (userhost->gcount == 0 && userhost->lcount == 0)
- {
- hash_del_userhost(userhost);
- mp_pool_release(userhost);
- }
-}
-
/*
* Safe list code.
*
--- /dev/null
+/*
+ * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
+ *
+ * Copyright (c) 2003-2016 ircd-hybrid development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+/*! \file userhost.c
+ * \brief Global user limits.
+ * \version $Id$
+ */
+
+#include "hash.h"
+#include "client.h"
+#include "userhost.h"
+#include "mempool.h"
+#include "irc_string.h"
+
+static mp_pool_t *userhost_pool = NULL;
+
+void
+userhost_init(void)
+{
+ userhost_pool = mp_pool_new("userhost", sizeof(struct UserHost), MP_CHUNK_SIZE_USERHOST);
+}
+
+/* count_user_host()
+ *
+ * inputs
+ * - hostname
+ * - pointer to where global count should go
+ * - pointer to where local count should go
+ * output - none
+ * side effects -
+ */
+void
+count_user_host(const char *host, unsigned int *global_p, unsigned int *local_p)
+{
+ struct UserHost *userhost = hash_find_userhost(host);
+
+ if (userhost == NULL)
+ return;
+
+ if (global_p != NULL)
+ *global_p = userhost->gcount;
+ if (local_p != NULL)
+ *local_p = userhost->lcount;
+}
+
+/* find_or_add_userhost()
+ *
+ * inputs - host name
+ * output - none
+ * side effects - find UserHost * for given host name
+ */
+static struct UserHost *
+find_or_add_userhost(const char *host)
+{
+ struct UserHost *userhost = hash_find_userhost(host);
+
+ if (userhost != NULL)
+ return userhost;
+
+ userhost = mp_pool_get(userhost_pool);
+
+ memset(userhost, 0, sizeof(*userhost));
+ strlcpy(userhost->host, host, sizeof(userhost->host));
+ hash_add_userhost(userhost);
+
+ return userhost;
+}
+
+/* add_user_host()
+ *
+ * inputs
+ * - hostname
+ * - int flag 1 if global, 0 if local
+ * output - none
+ * side effects - add given user@host to hash tables
+ */
+void
+add_user_host(const char *host, int global)
+{
+ struct UserHost *userhost = find_or_add_userhost(host);
+
+ if (userhost == NULL)
+ return;
+
+ ++userhost->gcount;
+
+ if (!global)
+ {
+ ++userhost->lcount;
+ }
+}
+
+/* delete_user_host()
+ *
+ * inputs
+ * - hostname
+ * - int flag 1 if global, 0 if local
+ * output - none
+ * side effects - delete given user@host to hash tables
+ */
+void
+delete_user_host(const char *host, int global)
+{
+ struct UserHost *userhost = hash_find_userhost(host);
+
+ if (userhost == NULL)
+ return;
+
+ if (userhost->gcount > 0)
+ --userhost->gcount;
+
+ if (!global)
+ if (userhost->lcount > 0)
+ --userhost->lcount;
+
+ if (userhost->gcount == 0 && userhost->lcount == 0)
+ {
+ hash_del_userhost(userhost);
+ mp_pool_release(userhost);
+ }
+}
+
+