]> jfr.im git - irc/rizon/plexus4.git/commitdiff
Split userhost stuff into its own file
authorAdam <redacted>
Mon, 10 Oct 2016 22:45:13 +0000 (18:45 -0400)
committerAdam <redacted>
Mon, 10 Oct 2016 22:45:13 +0000 (18:45 -0400)
include/hash.h
include/userhost.h
src/Makefile.am
src/hash.c
src/ircd.c
src/userhost.c [new file with mode: 0644]

index 1d4db912aa2dde77dc93f1517b49797bfd9a5aed..581d966b6616df04a310cdcbfa9f384746cb8b2c 100644 (file)
@@ -35,6 +35,7 @@
 struct Client;
 struct Channel;
 struct UserHost;
+struct ListTask;
 
 enum
 {
index a48e7e5871af74172e560d569f2574af943964e3..5bfee71bced5e31706cbbfb2bca342e6d84a81b0 100644 (file)
@@ -35,6 +35,7 @@ struct UserHost
   unsigned int lcount; /* Local user count on this addr */
 };
 
+extern void userhost_init(void);
 extern void count_user_host(const char *, unsigned int *, unsigned int *);
 extern void add_user_host(const char *, int);
 extern void delete_user_host(const char *, int);
index b5bbbda5ff2b3037083d89b0a7846c5c31854156..c4c520b2516510eec55b2404326b470cbf24393f 100644 (file)
@@ -75,6 +75,7 @@ libplexus_la_SOURCES =           \
                ssl.c             \
                sslverify.c       \
                upgrade.c         \
+               userhost.c        \
                version.c         \
                watch.c           \
                whowas.c
index 92a3f3131989dac7b363e4a7870d6b9c9faa83d8..ac6ae2f61183c57a5728591cb06da4433eb49fdb 100644 (file)
@@ -45,8 +45,6 @@
 #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
@@ -70,8 +68,6 @@ static struct UserHost *userhostTable[HASHSIZE];
 void
 hash_init(void)
 {
-  userhost_pool = mp_pool_new("userhost", sizeof(struct UserHost), MP_CHUNK_SIZE_USERHOST);
-
   hashf_xor_key = genrand_int32();
 }
 
@@ -500,106 +496,6 @@ hash_find_userhost(const char *host)
   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.
  *
index 9a4220dd80deed57ad1f18574bf29c8abae0ee49..b9e6260a93f671cf2f9bc57c0522c3f77d6d65d3 100644 (file)
@@ -65,6 +65,7 @@
 #include "scripting.h"
 #include "ssl.h"
 #include "httpd.h"
+#include "userhost.h"
 
 
 #ifdef HAVE_LIBGEOIP
@@ -496,6 +497,7 @@ plexus_main(int argc, char *argv[])
   init_isupport();
   dbuf_init();
   hash_init();
+  userhost_init();
   init_ip_hash_table();      /* client host ip hash table */
   init_host_hash();          /* Host-hashtable. */
   client_init();
diff --git a/src/userhost.c b/src/userhost.c
new file mode 100644 (file)
index 0000000..a07e048
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ *  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);
+  }
+}
+
+