]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Separated the authext functionality from the nick module.
authorsplidge <redacted>
Fri, 1 Jun 2007 23:59:31 +0000 (00:59 +0100)
committersplidge <redacted>
Fri, 1 Jun 2007 23:59:31 +0000 (00:59 +0100)
The new authext module does not depend on the irc module, which allows
modules which attach items to authexts to not depend on irc.  Perfect for
allowing the IRC module to be reloaded without having to reload your service
database.

authext/Makefile [new file with mode: 0644]
authext/authext.c [new file with mode: 0644]
authext/authext.h [new file with mode: 0644]
nick/nick.c
nick/nick.h
nick/nickalloc.c
nick/nickhelpers.c

diff --git a/authext/Makefile b/authext/Makefile
new file mode 100644 (file)
index 0000000..533f770
--- /dev/null
@@ -0,0 +1,6 @@
+
+.PHONY: all
+all: authext.so
+
+authext.so: authext.o
+       ld -shared -Bdynamic -o $@ $^
diff --git a/authext/authext.c b/authext/authext.c
new file mode 100644 (file)
index 0000000..e4eef2a
--- /dev/null
@@ -0,0 +1,165 @@
+#include "authext.h"
+#include "../core/nsmalloc.h"
+#include "../core/error.h"
+#include "../lib/sstring.h"
+#include "../lib/irc_string.h"
+
+#include <string.h>
+
+#define ALLOCUNIT 100
+
+#define authnamehash(x)   ((x)%AUTHNAMEHASHSIZE)
+
+authname *freeauthnames;
+authname *authnametable[AUTHNAMEHASHSIZE];
+
+sstring *authnameextnames[MAXAUTHNAMEEXTS];
+
+void _init() {
+  freeauthnames=NULL;
+  memset(authnametable,0,sizeof(authnametable));
+}
+
+void _fini() {
+  nsfreeall(POOL_AUTHEXT);
+}
+
+authname *newauthname() {
+  authname *anp;
+  int i;
+
+  if (freeauthnames==NULL) {
+    freeauthnames=(authname *)nsmalloc(POOL_AUTHEXT, ALLOCUNIT*sizeof(authname));
+    for (i=0;i<(ALLOCUNIT-1);i++) {
+      freeauthnames[i].next=&(freeauthnames[i+1]);
+    }
+    freeauthnames[ALLOCUNIT-1].next=NULL;
+  }
+
+  anp=freeauthnames;
+  freeauthnames=anp->next;
+
+  return anp;
+}
+
+void freeauthname (authname *anp) {
+  anp->next=freeauthnames;
+  freeauthnames=anp;
+}
+
+int registerauthnameext(const char *name) {
+  int i;
+
+  if (findauthnameext(name)!=-1) {
+    Error("nick",ERR_WARNING,"Tried to register duplicate authname extension %s",name);
+    return -1;
+  }
+
+  for (i=0;i<MAXAUTHNAMEEXTS;i++) {
+    if (authnameextnames[i]==NULL) {
+      authnameextnames[i]=getsstring(name,100);
+      return i;
+    }
+  }
+
+  Error("nick",ERR_WARNING,"Tried to register too many authname extensions: %s",name);
+  return -1;
+}
+
+int findauthnameext(const char *name) {
+  int i;
+
+  for (i=0;i<MAXAUTHNAMEEXTS;i++) {
+    if (authnameextnames[i]!=NULL && !ircd_strcmp(name,authnameextnames[i]->content)) {
+      return i;
+    }
+  }
+
+  return -1;
+}
+
+void releaseauthnameext(int index) {
+  int i;
+  authname *anp;
+
+  freesstring(authnameextnames[index]);
+  authnameextnames[index]=NULL;
+
+  for (i=0;i<AUTHNAMEHASHSIZE;i++) {
+    for (anp=authnametable[i];anp;anp=anp->next) {
+      anp->exts[index]=NULL;
+    }
+  }
+}
+
+authname *findauthname(unsigned long userid) {
+  authname *anp;
+
+  if(!userid)
+    return NULL;
+
+  for (anp=authnametable[authnamehash(userid)];anp;anp=(authname *)anp->next)
+    if (userid==anp->userid)
+      return anp;
+
+  return NULL;
+}
+
+authname *findorcreateauthname(unsigned long userid) {
+  authname *anp;
+  unsigned int thehash=authnamehash(userid);
+
+  if(!userid)
+    return NULL;
+
+  for (anp=authnametable[thehash];anp;anp=(authname *)anp->next)
+    if (userid==anp->userid)
+      return anp;
+
+  anp=newauthname();
+  anp->userid=userid;
+  anp->usercount=0;
+  anp->marker=0;
+  anp->nicks=NULL;
+  memset(anp->exts, 0, MAXAUTHNAMEEXTS * sizeof(void *));
+  anp->next=(struct authname *)authnametable[thehash];
+  authnametable[thehash]=anp;
+
+  return anp;
+}
+
+void releaseauthname(authname *anp) {
+  authname **manp;
+  int i;
+  if (anp->usercount==0) {
+    for(i=0;i<MAXAUTHNAMEEXTS;i++)
+      if(anp->exts[i]!=NULL)
+        return;
+
+    for(manp=&(authnametable[authnamehash(anp->userid)]);*manp;manp=(authname **)&((*manp)->next)) {
+      if ((*manp)==anp) {
+        (*manp)=(authname *)anp->next;
+        freeauthname(anp);
+        return;
+      }
+    }
+    Error("nick",ERR_ERROR,"Unable to remove authname %lu from hashtable",anp->userid);
+  }
+}
+
+unsigned int nextauthnamemarker() {
+  int i;
+  authname *anp;
+  static unsigned int authnamemarker=0;
+
+  authnamemarker++;
+  if (!authnamemarker) {
+    /* If we wrapped to zero, zap the marker on all records */
+    for (i=0;i<AUTHNAMEHASHSIZE;i++)
+      for (anp=authnametable[i];anp;anp=anp->next)
+        anp->marker=0;
+    authnamemarker++;
+  }
+
+  return authnamemarker;
+}
diff --git a/authext/authext.h b/authext/authext.h
new file mode 100644 (file)
index 0000000..ddc09c4
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef __AUTHEXT_H
+#define __AUTHEXT_H
+
+#define MAXAUTHNAMEEXTS 5
+
+struct nick;
+
+typedef struct authname {
+  unsigned long userid;
+  int usercount;
+  unsigned int marker;
+  struct nick *nicks;
+  struct authname *next;
+  /* These are extensions only used by other modules */
+  void *exts[MAXAUTHNAMEEXTS];
+} authname;
+
+#define AUTHNAMEHASHSIZE  60000
+
+extern authname *authnametable[AUTHNAMEHASHSIZE];
+
+/* Allocators */
+authname *newauthname();
+void freeauthname (authname *hp);
+
+/* EXT management */
+int registerauthnameext(const char *name);
+int findauthnameext(const char *name);
+void releaseauthnameext(int index);
+
+/* Actual user commands */
+authname *findauthname(unsigned long userid);
+authname *findorcreateauthname(unsigned long userid);
+void releaseauthname(authname *anp);
+
+/* Marker */
+unsigned int nextauthnamemarker();
+
+#endif
index 2b949d971f4e872adda4db9a73c13b66a440e1e5..9b47eef72b5fb199a2b1bda6620317235530945c 100644 (file)
@@ -42,7 +42,6 @@ nick **servernicks[MAXSERVERS];
 sstring *nickextnames[MAXNICKEXTS];
 sstring *nodeextnames[PATRICIA_MAXSLOTS];
 patricia_tree_t *iptree;
-sstring *authnameextnames[MAXAUTHNAMEEXTS];
 
 void nickstats(int hooknum, void *arg);
 
@@ -267,51 +266,6 @@ void releasenickext(int index) {
   }
 }
 
-int registerauthnameext(const char *name) {
-  int i;
-  
-  if (findauthnameext(name)!=-1) {
-    Error("nick",ERR_WARNING,"Tried to register duplicate authname extension %s",name);
-    return -1;
-  }
-  
-  for (i=0;i<MAXAUTHNAMEEXTS;i++) {
-    if (authnameextnames[i]==NULL) {
-      authnameextnames[i]=getsstring(name,100);
-      return i;
-    }
-  }
-  
-  Error("nick",ERR_WARNING,"Tried to register too many authname extensions: %s",name);
-  return -1;
-}
-
-int findauthnameext(const char *name) {
-  int i;
-  
-  for (i=0;i<MAXAUTHNAMEEXTS;i++) {
-    if (authnameextnames[i]!=NULL && !ircd_strcmp(name,authnameextnames[i]->content)) {
-      return i;
-    }
-  }
-  
-  return -1;
-}
-
-void releaseauthnameext(int index) {
-  int i;
-  authname *anp;
-  
-  freesstring(authnameextnames[index]);
-  authnameextnames[index]=NULL;
-  
-  for (i=0;i<AUTHNAMEHASHSIZE;i++) {
-    for (anp=authnametable[i];anp;anp=anp->next) {
-      anp->exts[index]=NULL;
-    }
-  }
-}
-
 /* visiblehostmask
  *  Produces the "apparent" hostmask as seen by network users.
  */
index f57cbc5f746e5df047f381a91fe9998632b0a107..28394cd7030b759d5eb49391cd997b3252349132 100644 (file)
 #include "../lib/base64.h"
 #include "../lib/irc_ipv6.h"
 #include "../lib/patricia.h"
+
+#include "../authext/authext.h"
+
 #include <time.h>
 
 #define MAXNICKEXTS       6
-#define MAXAUTHNAMEEXTS   5
 
 #define UMODE_INV       0x0001
 #define UMODE_WALLOPS   0x0002
@@ -90,16 +92,6 @@ typedef struct realname {
   struct realname *next;
 } realname;
 
-typedef struct authname {
-  unsigned long userid;
-  int usercount;
-  unsigned int marker;
-  struct nick *nicks;
-  struct authname *next;
-  /* These are extensions only used by other modules */
-  void *exts[MAXAUTHNAMEEXTS];
-} authname;
-
 typedef struct nick {
   char nick[NICKLEN+1];
   long numeric;
@@ -129,13 +121,11 @@ typedef struct nick {
 #define NICKHASHSIZE      60000
 #define HOSTHASHSIZE      40000
 #define REALNAMEHASHSIZE  40000
-#define AUTHNAMEHASHSIZE  60000
 
 extern nick *nicktable[NICKHASHSIZE];
 extern nick **servernicks[MAXSERVERS];
 extern host *hosttable[HOSTHASHSIZE];
 extern realname *realnametable[REALNAMEHASHSIZE];
-extern authname *authnametable[AUTHNAMEHASHSIZE];
 extern const flag umodeflags[];
 extern patricia_tree_t *iptree;
 
@@ -159,8 +149,6 @@ nick *newnick();
 void freenick (nick *np);
 host *newhost();
 void freehost (host *hp);
-authname *newauthname();
-void freeauthname (authname *hp);
 
 /* nick.c functions */
 void handleserverchange(int hooknum, void *arg);
@@ -171,9 +159,6 @@ nick *getnickbynick(const char *nick);
 int registernickext(const char *name);
 int findnickext(const char *name);
 void releasenickext(int index);
-int registerauthnameext(const char *name);
-int findauthnameext(const char *name);
-void releaseauthnameext(int index);
 char *visiblehostmask(nick *np, char *buf);
 int registernodeext(const char *name);
 int findnodeext(const char *name);
@@ -202,13 +187,9 @@ void releasehost(host *hp);
 realname *findrealname(const char *name);
 realname *findorcreaterealname(const char *name);
 void releaserealname(realname *rnp);
-authname *findauthname(unsigned long userid);
-authname *findorcreateauthname(unsigned long userid);
-void releaseauthname(authname *anp);
 
 unsigned int nexthostmarker();
 unsigned int nextrealnamemarker();
-unsigned int nextauthnamemarker();
 unsigned int nextnickmarker();
 
 #endif
index 395aec0a751a19a063a5582a579ce4df753465f6..1f7031c1712dde97b153ce496bc4840a837162d8 100644 (file)
 
 nick *freenicks;
 host *freehosts;
-authname *freeauthnames;
 
 void initnickalloc() {
   freenicks=NULL;
   freehosts=NULL;
-  freeauthnames=NULL;
   
   assert(sizeof(host)==sizeof(realname));
 }
@@ -75,25 +73,3 @@ void freehost (host *hp) {
   freehosts=hp;
 }
 
-authname *newauthname() {
-  authname *anp;
-  int i;
-  
-  if (freeauthnames==NULL) {
-    freeauthnames=(authname *)malloc(ALLOCUNIT*sizeof(authname));
-    for (i=0;i<(ALLOCUNIT-1);i++) {
-      freeauthnames[i].next=&(freeauthnames[i+1]);
-    }
-    freeauthnames[ALLOCUNIT-1].next=NULL;
-  }
-  
-  anp=freeauthnames;
-  freeauthnames=anp->next;
-  
-  return anp;
-}
-
-void freeauthname (authname *anp) {
-  anp->next=freeauthnames;
-  freeauthnames=anp;
-}
index 9ba2f48fb198d8b613c48eee4e22d9771c3d8607..ac660002a82add35e9b700e6923940a6821c14bb 100644 (file)
 
 #define hosthash(x)       ((crc32i(x))%HOSTHASHSIZE)
 #define realnamehash(x)   ((crc32(x))%REALNAMEHASHSIZE)
-#define authnamehash(x)   ((x)%AUTHNAMEHASHSIZE)
 
 host *hosttable[HOSTHASHSIZE];
 realname *realnametable[REALNAMEHASHSIZE];
-authname *authnametable[AUTHNAMEHASHSIZE];
 
 void initnickhelpers() {
   memset(hosttable,0,sizeof(hosttable));
   memset(realnametable,0,sizeof(realnametable));
-  memset(authnametable,0,sizeof(authnametable));
 }
 
 host *findhost(const char *hostname) {
@@ -114,61 +111,6 @@ void releaserealname(realname *rnp) {
   }
 }
 
-authname *findauthname(unsigned long userid) {
-  authname *anp;
-  
-  if(!userid)
-    return NULL;
-
-  for (anp=authnametable[authnamehash(userid)];anp;anp=(authname *)anp->next)
-    if (userid==anp->userid)
-      return anp;
-      
-  return NULL;
-}
-
-authname *findorcreateauthname(unsigned long userid) {
-  authname *anp;
-  unsigned int thehash=authnamehash(userid);
-  
-  if(!userid)
-    return NULL;
-
-  for (anp=authnametable[thehash];anp;anp=(authname *)anp->next)
-    if (userid==anp->userid)
-      return anp;
-  
-  anp=newauthname();
-  anp->userid=userid;
-  anp->usercount=0;
-  anp->marker=0;
-  anp->nicks=NULL;
-  memset(anp->exts, 0, MAXAUTHNAMEEXTS * sizeof(void *));
-  anp->next=(struct authname *)authnametable[thehash];
-  authnametable[thehash]=anp;
-  
-  return anp;
-}
-
-void releaseauthname(authname *anp) {
-  authname **manp;
-  int i;
-  if (anp->usercount==0) {
-    for(i=0;i<MAXAUTHNAMEEXTS;i++)
-      if(anp->exts[i]!=NULL)
-        return;
-    
-    for(manp=&(authnametable[authnamehash(anp->userid)]);*manp;manp=(authname **)&((*manp)->next)) {
-      if ((*manp)==anp) {
-        (*manp)=(authname *)anp->next;
-        freeauthname(anp);
-        return;
-      }
-    }
-    Error("nick",ERR_ERROR,"Unable to remove authname %lu from hashtable",anp->userid);
-  }
-}
-
 unsigned int nexthostmarker() {        
   int i;
   host *hp;
@@ -203,23 +145,6 @@ unsigned int nextrealnamemarker() {
   return realnamemarker;
 }
 
-unsigned int nextauthnamemarker() {
-  int i;
-  authname *anp;
-  static unsigned int authnamemarker=0;
-  
-  authnamemarker++;
-  if (!authnamemarker) {
-    /* If we wrapped to zero, zap the marker on all records */
-    for (i=0;i<AUTHNAMEHASHSIZE;i++)
-      for (anp=authnametable[i];anp;anp=anp->next) 
-        anp->marker=0;
-    authnamemarker++;
-  }
-  
-  return authnamemarker;
-}
-
 unsigned int nextnickmarker() {
   int i;
   nick *np;